How to Intermediate · 3 min read

AWS Bedrock migration guide

Quick answer
To migrate to AWS Bedrock, set up the boto3 client for bedrock-runtime with your AWS credentials, then use the converse method to interact with Bedrock models. Replace your existing LLM API calls with Bedrock's converse interface, specifying the Bedrock model ID and message format.

PREREQUISITES

  • Python 3.8+
  • AWS CLI configured with credentials
  • pip install boto3

Setup

Install the boto3 library and configure your AWS credentials with appropriate permissions for Bedrock. Set your AWS region to one that supports Bedrock, such as us-east-1.
bash
pip install boto3
output
Collecting boto3
  Downloading boto3-1.28.0-py3-none-any.whl (134 kB)
Installing collected packages: boto3
Successfully installed boto3-1.28.0

Step by step

Use the boto3 bedrock-runtime client to call the converse API. Provide the modelId for your target Bedrock model and format messages as a list of role-content dictionaries.
python
import boto3
import json

# Initialize Bedrock client
client = boto3.client('bedrock-runtime', region_name='us-east-1')

# Define the model ID (replace with your Bedrock model)
model_id = 'anthropic.claude-3-5-sonnet-20241022-v2:0'

# Prepare messages
messages = [
    {"role": "user", "content": "Hello, how can I use AWS Bedrock?"}
]

# Format request body
body = json.dumps({
    "anthropic_version": "bedrock-2023-05-31",
    "max_tokens": 512,
    "messages": messages
})

# Call Bedrock converse API
response = client.invoke_model(
    modelId=model_id,
    body=body
)

# Parse response
output = json.loads(response['body'])
print("Response:", output['completions'][0]['data']['text'])
output
Response: AWS Bedrock lets you easily integrate foundation models into your applications with secure, scalable APIs.

Common variations

Use different Bedrock models by changing modelId, e.g., amazon.titan-text-express-v1. Adjust max_tokens and other parameters in the request body JSON. For asynchronous calls, use aiobotocore or AWS SDKs supporting async.

Troubleshooting

If you get AccessDeniedException, verify your IAM permissions include Bedrock access. For ModelNotFoundException, confirm the modelId is correct and available in your region. Timeouts may require increasing client timeout settings or checking network connectivity.

Key Takeaways

  • Use boto3 with bedrock-runtime client to migrate existing LLM calls to AWS Bedrock.
  • Replace your LLM API calls with invoke_model and format messages as JSON in the request body.
  • Ensure AWS credentials and IAM permissions are correctly configured for Bedrock access.
  • Test with different Bedrock models by changing the modelId parameter.
  • Handle common errors by verifying permissions, model availability, and network settings.
Verified 2026-04 · anthropic.claude-3-5-sonnet-20241022-v2:0, amazon.titan-text-express-v1
Verify ↗