How to beginner · 3 min read

How to get started with AWS Bedrock

Quick answer
To get started with AWS Bedrock, use the boto3 Python client with the bedrock-runtime service. Initialize the client, then call converse or invoke_model with your chosen Bedrock model ID and chat messages to generate AI completions.

PREREQUISITES

  • Python 3.8+
  • AWS account with Bedrock access
  • AWS CLI configured or environment variables for AWS credentials
  • pip install boto3

Setup

Install the boto3 library to interact with AWS Bedrock. Ensure your AWS credentials are configured via ~/.aws/credentials or environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. You also need Bedrock access enabled in your AWS account.

bash
pip install boto3

Step by step

This example shows how to create a boto3 client for Bedrock and send a chat completion request using the converse method with a Claude model. Replace modelId with your Bedrock model identifier.

python
import os
import boto3

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

# Define model ID and messages
model_id = 'anthropic.claude-3-5-sonnet-20241022-v2:0'
messages = [
    {"role": "user", "content": [{"type": "text", "text": "Hello, AWS Bedrock!"}]}
]

# Call converse API
response = client.converse(
    modelId=model_id,
    messages=messages,
    maxTokens=100
)

# Extract and print the AI response
print(response['message']['content'][0]['text'])
output
Hello, AWS Bedrock! How can I assist you today?

Common variations

  • Use invoke_model for raw JSON payloads instead of converse.
  • Change modelId to other Bedrock models like amazon.titan-text-express-v1 or meta.llama3-1-70b-instruct-v1:0.
  • Adjust maxTokens and other parameters for response length and temperature.
  • Use AWS SDK async clients or other languages as needed.

Troubleshooting

  • If you get AccessDeniedException, verify your AWS IAM permissions include Bedrock access.
  • For ModelNotFoundException, confirm the modelId is correct and available in your region.
  • Ensure your AWS credentials are properly configured and environment variables are set.
  • Check your AWS region matches the Bedrock service availability.

Key Takeaways

  • Use the boto3 client with service name 'bedrock-runtime' to access AWS Bedrock.
  • Call the 'converse' method with modelId and messages for chat completions.
  • Configure AWS credentials and region properly to avoid access errors.
Verified 2026-04 · anthropic.claude-3-5-sonnet-20241022-v2:0, amazon.titan-text-express-v1, meta.llama3-1-70b-instruct-v1:0
Verify ↗