🧱How to use Amazon Bedrock with Python (boto3)

Published: (January 7, 2026 at 03:13 PM EST)
1 min read
Source: Dev.to

Source: Dev.to

🧰 Requirements

  • Python 3.9+
  • AWS account with Bedrock enabled
  • AWS credentials configured (CLI, environment variables, or IAM role)

📦 Install boto3

pip install boto3

🧠 Python example: Claude on Amazon Bedrock

import boto3
import json

client = boto3.client(
    "bedrock-runtime",
    region_name="us-east-1"
)

payload = {
    "prompt": "Human: Explain what Amazon Bedrock is in simple terms.\nAssistant:",
    "max_tokens_to_sample": 200
}

response = client.invoke_model(
    modelId="anthropic.claude-v2",
    body=json.dumps(payload)
)

result = response["body"].read().decode("utf-8")
print(result)

🔍 What’s happening here?

  • bedrock-runtime is used to call foundation models.
  • invoke_model() sends a prompt to Claude.
  • The response is streamed back and decoded.

🚀 Final thoughts

Amazon Bedrock + Python is a powerful combo for building AI‑powered applications quickly and securely.

Perfect for:

  • AI assistants
  • Knowledge bots
  • Cloud‑native AI projects
Back to Blog

Related posts

Read more »

Hello, Newbie Here.

Hi! I'm falling back into the realm of S.T.E.M. I enjoy learning about energy systems, science, technology, engineering, and math as well. One of the projects I...