Skip to main content
In this lesson we cover how to integrate Amazon Bedrock with Amazon S3 to apply generative AI at scale to files stored in the cloud. We’ll follow this sequence:
  • Define the problem (difficulty processing existing data)
  • Describe the solution pattern (S3 as input/output, Bedrock for inference)
  • Show example code using the AWS SDK (boto3)
  • Walk through a short demo (console view)
  • Summarize next steps and expected outcomes
A slide titled "Lecture Flow" showing a blue flowchart of rounded boxes: Problem → Solution → Workflow → Demonstration → Results → Key Takeaway → What's Next. The boxes include notes about using Amazon S3, accessing S3 with the SDK, and applying AI to data in S3.
Problem Most organizations have large volumes of text data—documents, reports, logs, call transcripts, and customer feedback—scattered across many files. Manually reading and summarizing this content is slow and doesn’t scale: what works for 100 documents won’t work for 100,000. We need a reliable, scalable pattern to apply generative AI (summarization, transformation, sentiment analysis, classification, etc.) directly to data stored in S3 so processing can be automated and parallelized.
A slide titled "Problem: Difficult to Process Existing Data" that lists three types of stored text data—documents and reports, logs and transcripts, and customer feedback files—and briefly describes each. A highlighted footer notes the key need for organizations to apply AI to summarize, analyze, or transform this data without manual effort.
Solution: Use Amazon S3 with Bedrock A common, scalable pattern is:
  • Store source files in S3 (use buckets or prefixes to organize by team/use-case).
  • Read objects from S3 in your application or serverless function.
  • Send the file contents to Amazon Bedrock (invoke the chosen foundation model) for inference.
  • Write generated outputs back to S3 (use a separate prefix or bucket for outputs).
  • Optionally trigger the pipeline automatically using S3 Event Notifications (to Lambda, SQS, or SNS) for event-driven processing.
This pattern treats S3 as the durable storage layer (input + output), with the application layer responsible for calling Bedrock and handling orchestration.
A presentation slide titled "Solution: Use Amazon S3 Integration" with a large S3 bucket icon at the top. Below it are four circular icons and labels: "Store input documents," "Store output results," "Trigger processing via events," and "Integrate with Retrieval Augmentation."
S3 pattern at a glance Code example (single-file, single-object) This compact Python example uses boto3 to:
  1. Read a text object from S3
  2. Call the Bedrock runtime (invoke_model) with a chat-style messages payload
  3. Parse the model response (with flexible extraction to handle different model response shapes)
  4. Write the generated summary back to S3
Replace bucket names, keys, and the modelId with values appropriate for your environment. Ensure your AWS credentials and region are configured (via environment variables, shared credentials file, or an IAM role).
How this works (step-by-step)
  1. s3.get_object(…) reads the object from the specified S3 bucket/key and returns a streaming Body; the example reads and decodes it into a string.
  2. brt.invoke_model(…) sends a JSON payload to the Bedrock runtime. This includes chat-style messages and inference parameters such as max_tokens and temperature.
  3. Models can return responses in different JSON shapes. The example includes multiple checks to extract the generated text; adjust extraction to match your model’s response format.
  4. s3.put_object(…) writes the generated summary back to S3. Use a dedicated output prefix (for example, output/summary.txt) to keep inputs and outputs organized.
S3 terminology tip: files in S3 are called “objects” and are identified by object keys. Use logical prefixes such as input/ and output/ (or separate buckets) to separate source data from generated results and simplify processing.
Scaling to multiple files The same pattern scales to many objects. Below is a simple iteration pattern: list objects under an input/ prefix, process each file, and write results under an output/ prefix. In production, add proper error handling, pagination, retries, rate limiting, and parallelization.
Production considerations: monitor and control model usage to avoid unexpected costs, add retries/backoff for transient errors, paginate list_objects_v2 results, and ensure the IAM role or credentials used have least-privilege access to the relevant S3 buckets and Bedrock APIs.
Demo walkthrough (console) In the demo bucket shown in the console, there are two prefixes: Input and Output. The Input folder contains a file with ten short customer reviews that we can use as sample input. The processing code reads that file from S3, sends it to Bedrock for summarization (or sentiment analysis), and writes the generated results back to the Output prefix.
A dark-themed computer screen showing a text file of ten numbered customer reviews, with a large white mouse cursor visible near the left. The reviews are short praise/complaint lines about a product.
At scale, replace the simple listing loop with an event-driven approach using S3 Event Notifications:
  • New object uploaded -> S3 Event Notification -> Lambda / SQS -> worker consumes message and calls Bedrock
  • Or use a batch worker that polls SQS to process many files in parallel
Next steps Consider expanding this S3 + Bedrock pattern with:
  • Retrieval-augmented generation (RAG) and semantic search (index embeddings for fast lookup)
  • Preprocessing for binary formats (extract text from PDFs, Word documents, images with OCR)
  • Robust orchestration (Step Functions, SQS, or containerized workers) for higher throughput and retry semantics
  • Monitoring, billing alerts, and logging for model usage
Links and references

Watch Video