Web playgrounds are great for demos. You paste a block of text, watch the model generate a neat summary, and close the tab. But that is not engineering. Production work means APIs, error handling, and code that runs while you sleep. If you need to churn through meeting transcripts, support tickets, or research papers on a schedule, you need a pipeline.

This guide walks through building exactly that: a lightweight, automated document summarization script using Python, the AWS SDK for Python (boto3), and Amazon Bedrock. We will use Anthropic’s Claude 3 Haiku, a model that hits the sweet spot of speed and cost for text summarization tasks.

Why Bedrock and Claude 3 Haiku?

Amazon Bedrock is a managed service that exposes foundation models through a single set of AWS APIs. Instead of piecing together external endpoints and wrestling with separate billing and security models, you call an AWS endpoint with standard IAM controls. Your data stays within your AWS environment.

Claude 3 Haiku is the leanest model in Anthropic’s Claude 3 family. It is built for responsiveness and low cost, which makes it ideal for high-volume summarization where you want predictable output without paying for the horsepower of larger models on simple reading tasks.

What You Need

Before writing any code, make sure you have the following ready:

  • An active AWS account.
  • Python 3.9 or higher installed locally.
  • The AWS CLI configured with credentials that have permission to invoke Bedrock models. If you have not run aws configure yet, do that now. If you hit permission errors later, you will likely need to attach the appropriate Bedrock invocation permissions to your IAM user or role.
  • Model access enabled specifically for Anthropic Claude 3 Haiku inside the AWS Bedrock console. AWS requires you to explicitly opt in for each model provider before you can call it.

Step 1: Enable Model Access

Bedrock does not let you call models out of the box. You must flip the switch in the console first.

  1. Log into the AWS Management Console.
  2. Use the search bar to find Amazon Bedrock.
  3. In the left navigation panel, select Model access.
  4. Click Modify model access.
  5. Tick the box for Anthropic (Claude 3 Haiku) and submit your request.

Once the status flips to "Access granted," you are clear to call the model from code.

Step 2: Set Up Your Environment

A clean Python environment keeps dependencies isolated and reproducible. Open your terminal and run these commands:

mkdir bedrock-summarizer && cd bedrock-summarizer
python3 -m venv venv
source venv/bin/activate
pip install boto3

Windows users should replace the activation command with venv\Scripts\activate. After pip install boto3 finishes, you have everything you need to talk to AWS APIs.

Step 3: Write the Script

Create a file named summarize.py. The goal is to read a document from disk, hand it to the Bedrock Converse API, and print a concise summary.

Below is a complete, working implementation. We use the Converse API because it abstracts away the raw JSON formatting that different model providers expect. You simply pass a list of messages and inference settings.

import boto3

def summarize_document(text: str) -> str:
    client = boto3.client("bedrock-runtime")
    
    model_id = "anthropic.claude-3-haiku-20240307-v1:0"
    
    messages = [
        {
            "role": "user",
            "content": [
                {
                    "text": (
                        "Provide a concise summary of the following document. "
                        "Focus on the main points and avoid unnecessary detail:\n\n"
                        f"{text}"
                    )
                }
            ]
        }
    ]
    
    response = client.converse(
        modelId=model_id,
        messages=messages,
        inferenceConfig={
            "temperature": 0.3,
            "maxTokens": 512
        }
    )
    
    summary = response["output"]["message"]["content"][0]["text"]
    return summary.strip()


if __name__ == "__main__":
    with open("document.txt", "r", encoding="utf-8") as f:
        document_text = f.read()
    
    result = summarize_document(document_text)
    print("\n--- Summary ---\n")
    print(result)

A few practical details worth highlighting here:

  • boto3.client("bedrock-runtime") targets the runtime endpoint that handles inference. Make sure your AWS region in ~/.aws/config supports Bedrock and that you enabled Haiku in that same region.
  • Model ID anthropic.claude-3-haiku-20240307-v1:0 is the exact identifier Bedrock expects. Copy it precisely.
  • Temperature set to 0.3 keeps the output grounded. For summarization, you want consistency and fidelity to the source text, not creative embellishment. If you raise the temperature toward 1.0, the model starts taking liberties with phrasing and occasionally invents details.
  • The prompt itself is specific. Instead of throwing raw text at the model with a vague "summarize this," we explicitly ask for main points and instruct it to skip fluff. That kind of clarity separates unusable output from something you can actually ship.

Place any text file you want to summarize in the same directory and name it document.txt.

Step 4: Run It

With your virtual environment active, execute:

python summarize.py

If your credentials and model access are correct, you should see a tidy summary printed to your terminal within a few seconds. If you get an access error, double-check your IAM permissions and confirm you enabled Claude 3 Haiku in the console.

Pushing Beyond the Script

This pipeline is intentionally simple, but it is the foundation for real automation. Here is how you can extend it without adding bloat.

Batch processing. Swap the single file read for a loop over a directory. Drop fifty PDFs or text files into an input folder, iterate through them, and write the summaries to an output folder. If you want to ingest PDFs directly, you will need a preprocessing step with a library like PyPDF2 or pdfplumber to extract raw text before it hits Bedrock.

Chunking strategy. Very long documents may exceed the model’s context limit. When that happens, split the text into logical chunks by paragraph or section, summarize each chunk individually, and then pass the intermediate summaries back through the model for a final synthesis. This two-stage approach keeps you under token limits while preserving coverage of the full document.

Error handling. Production code should catch boto3.exceptions.ClientError specifically. AWS may throttle your requests if you call the API too aggressively. Wrap your converse call in a retry loop with exponential backoff, or use a library like tenacity to handle rate limits gracefully.

Prompt engineering. The difference between a mediocre summary and a useful one often comes down to the prompt. Ask for bullet points if you need scanability. Ask for a one-paragraph executive summary if the audience is senior leadership. You can even pass formatting constraints, such as "Limit the summary to three sentences" or "Return the output as JSON with keys for topic, key_points, and action_items."

The Real Takeaway

Moving from a chat playground to a working script is the inflection point where AI becomes infrastructure. Once this pipeline runs locally, you can lift it into an AWS Lambda function triggered by S3 uploads, schedule it on ECS Fargate, or hook it into an existing data workflow. The API call is the easy part. The engineering value comes from wrapping that call in logic that handles files, errors, and formatting so you never have to copy and paste text into a browser again.

For additional context and variations on this setup, see the original walkthrough on Dev.to. If you want to discuss AWS architectures, LLM pipelines, or prompt engineering with a community of builders, join the conversation over at [GyaanSetu AI on Telegram](https://t.me/GyaanSet