- reads a text file from Amazon S3,
- uses Amazon Bedrock to generate a concise summary,
- writes the summary back to S3.
Ensure your environment has valid AWS credentials and IAM permissions for S3 and Amazon Bedrock Runtime. Install
boto3 (for example, pip install boto3) and set AWS_REGION if necessary. See the Amazon Bedrock overview for service details.- Configure constants: region, bucket, S3 keys, and model identifier.
- Initialize boto3 clients for S3 and Bedrock Runtime.
- Read input text from S3.
- Build a concise summarization prompt and call Bedrock’s runtime.
- Parse the model response and write the generated summary back to S3.
Complete Python script
- Save as
read_generate_write_s3.py. - The script is minimal but includes robust parsing for common Bedrock response shapes.
Terminal example (trimmed)
- Use the S3 console: https://s3.console.aws.amazon.com/s3/home
- Or the AWS CLI:
aws s3 cp s3://kodekloud-intro-bedrock/output/customer_reviews_summary.txt -
- Scales from single-file processing to batch/stream workflows.
- Use S3 as a persistent, cost-effective storage layer for raw inputs and processed outputs.
- Trigger options: scheduled jobs, S3 events + Lambda, containerized consumers, or stream processors.
- Tune prompt engineering and model parameters (
temperature,maxTokensToSample) to adjust style and length.
Check your IAM policies: you need permissions to read/write the S3 objects and permission to call Bedrock Runtime APIs. If you see access denied errors, verify the role or credentials used by your environment (CLI, EC2, Lambda, or container).
- If you need finer-grained control over streaming outputs or different Bedrock integrations, some SDKs or model adapters may expose other method names (for example,
converse) or different response envelopes—adapt the parsing logic accordingly. - Useful links:
- Amazon Bedrock user guide
- boto3 S3 client
- boto3 clients: bedrock-runtime (if available for your SDK version)
- Programmatic summarization and extraction enable teams to unlock insights from existing text data without manual aggregation.
- The pattern is adaptable to many text-processing tasks (classification, extraction, QA) and integrates naturally with analytics or downstream automation.

- Run the sample script against your own bucket and input files.
- Experiment with different prompts, model IDs, and inferenceConfig parameters.
- Integrate the pattern into a production flow: S3 events + Lambda, step functions, or batch jobs.
