🧱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 »

Rapg: TUI-based Secret Manager

We've all been there. You join a new project, and the first thing you hear is: > 'Check the pinned message in Slack for the .env file.' Or you have several .env...

Technology is an Enabler, not a Saviour

Why clarity of thinking matters more than the tools you use Technology is often treated as a magic switch—flip it on, and everything improves. New software, pl...