🟠Claude on Amazon Bedrock
Run Claude through AWS Bedrock — setup, IAM, and API differences
Claude on Amazon Bedrock
What is Amazon Bedrock?
Amazon Bedrock is a fully managed AWS service that gives you access to generative AI models from multiple providers — including Claude from Anthropic — through a unified API. Instead of calling Anthropic directly, you use Claude through AWS infrastructure.
Think of Bedrock as a "marketplace" for AI models inside AWS. You pick the model you want, and AWS handles everything else — infrastructure, scaling, and security.
Why Use Claude Through Bedrock?
There are compelling reasons why organizations prefer Bedrock over calling Anthropic directly:
| Benefit | Explanation |
|---|---|
| Data stays in AWS | Your data never leaves the AWS environment — critical for compliance and privacy |
| Single bill | Pay for everything on your existing AWS invoice — no separate Anthropic account needed |
| Compliance | Bedrock supports HIPAA, SOC2, GDPR, and other compliance standards |
| AWS integration | Integrates natively with Lambda, S3, CloudWatch, IAM |
| Private VPC | Run everything inside your private network via PrivateLink |
| Access control | Use your existing IAM policies to manage who can call Claude |
Enabling Claude Models in Bedrock Console
Before you can use Claude through Bedrock, you need to enable model access in your account:
- Open the AWS Console
- Search for Amazon Bedrock
- Go to Model access from the sidebar
- Find Anthropic in the provider list
- Select the models you want to enable:
- Claude Opus 4
- Claude Sonnet 4
- Claude Haiku (3.5)
- Click Request model access
- Wait for approval (usually instant for some models)
Note: Not all models are available in every AWS region. Check availability in your region before planning your architecture.
IAM Permissions Setup
To use Bedrock, you need proper IAM permissions. Here is a basic IAM policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": "arn:aws:bedrock:*::foundation-model/anthropic.*"
}
]
}This policy allows invoking Anthropic models only. To restrict further, you can specify the region and model:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-sonnet-4-6-20250514-v1:0"
}
]
}For administrative access to manage models:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:ListFoundationModels",
"bedrock:GetFoundationModel",
"bedrock:ListModelAccessPermissions",
"bedrock:PutModelAccessPermission"
],
"Resource": "*"
}
]
}Model IDs on Bedrock
Model names in Bedrock differ from the direct Anthropic API names:
| Anthropic Model | Bedrock Model ID |
|---|---|
| claude-opus-4-6-20250514 | anthropic.claude-opus-4-6-20250514-v1:0 |
| claude-sonnet-4-6-20250514 | anthropic.claude-sonnet-4-6-20250514-v1:0 |
| claude-haiku-3-5-20241022 | anthropic.claude-3-5-haiku-20241022-v1:0 |
Important: Always use the full Bedrock model ID when invoking a model. Do not use the short Anthropic names.
Using the Anthropic SDK with Bedrock
The easiest way to use Claude on Bedrock is through the official Anthropic SDK with Bedrock configuration.
Installation — Python:
pip install anthropic[bedrock]Installation — TypeScript:
npm install @anthropic-ai/sdk @anthropic-ai/bedrock-sdkPython Example:
from anthropic import AnthropicBedrock
client = AnthropicBedrock(
aws_region="us-east-1",
)
message = client.messages.create(
model="anthropic.claude-sonnet-4-6-20250514-v1:0",
max_tokens=1024,
messages=[
{"role": "user", "content": "What is the capital of France?"}
]
)
print(message.content[0].text)TypeScript Example:
const client = new AnthropicBedrock({
awsRegion: "us-east-1",
});
const message = await client.messages.create({
model: "anthropic.claude-sonnet-4-6-20250514-v1:0",
max_tokens: 1024,
messages: [
{ role: "user", content: "What is the capital of France?" }
],
});
console.log(message.content[0].text);Configuring Credentials
The SDK automatically picks up AWS credentials from multiple sources in the following order:
- Environment variables:
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_REGION="us-east-1"- AWS credentials file:
aws configure-
IAM Role (on EC2, Lambda, or ECS) — the recommended approach for production
-
Passed directly in code:
client = AnthropicBedrock(
aws_access_key="AKIAIOSFODNN7EXAMPLE",
aws_secret_key="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
aws_region="us-east-1",
)Warning: Never hardcode access keys in production code. Use IAM Roles or AWS Secrets Manager instead.
API Differences: Bedrock vs Direct Anthropic API
While the Anthropic SDK unifies much of the interface, there are key differences:
| Aspect | Direct Anthropic API | Amazon Bedrock |
|---|---|---|
| Authentication | API key | AWS credentials (IAM) |
| Model IDs | claude-sonnet-4-6-20250514 | anthropic.claude-sonnet-4-6-20250514-v1:0 |
| Endpoint | api.anthropic.com | bedrock-runtime.{region}.amazonaws.com |
| Billing | Anthropic invoice | AWS invoice |
| Rate limits | Based on Anthropic plan | Based on AWS quotas |
| Model availability | All models | Depends on region |
| New features | Available immediately | May have a short delay |
Regional vs Global Endpoints
In Bedrock, each AWS region has its own endpoint:
bedrock-runtime.us-east-1.amazonaws.com
bedrock-runtime.us-west-2.amazonaws.com
bedrock-runtime.eu-west-1.amazonaws.com
bedrock-runtime.ap-northeast-1.amazonaws.com
Considerations for choosing a region:
- Closest geographically = lowest latency
- Model availability — not all models are available in every region
- Compliance requirements — some data must stay in specific regions (e.g., GDPR requires EU)
- Capacity — some regions have higher throughput than others
Cross-Region Inference
The Cross-Region Inference feature allows Bedrock to distribute requests across multiple regions automatically:
# Using a Cross-Region Inference Profile
client = AnthropicBedrock(
aws_region="us-east-1",
)
message = client.messages.create(
model="us.anthropic.claude-sonnet-4-6-20250514-v1:0",
max_tokens=1024,
messages=[
{"role": "user", "content": "Explain quantum computing"}
]
)Notice the us. prefix on the model ID — this activates Cross-Region Inference across US regions.
Benefits of Cross-Region Inference:
- Higher availability — if one region is busy, the request routes to another
- Greater throughput — leverage capacity across multiple regions
- Fully transparent — no code changes needed (just change the model ID)
Pricing Differences
Pricing on Bedrock is similar to the direct API but has its own structure:
| Model | Input Price (Anthropic) | Input Price (Bedrock) |
|---|---|---|
| Claude Sonnet 4 | $3 / million tokens | $3 / million tokens |
| Claude Opus 4 | $15 / million tokens | $15 / million tokens |
| Claude Haiku 3.5 | $0.80 / million tokens | $0.80 / million tokens |
Note: Prices are subject to change. Always check the AWS Bedrock pricing page and Anthropic pricing page for current rates.
Pricing options on Bedrock:
- On-Demand — pay only for what you use with no commitments
- Provisioned Throughput — reserve a fixed capacity at a lower per-token price
- Commitment pricing — discounts for long-term commitments
Streaming Responses on Bedrock
Bedrock supports response streaming just like the direct API:
Python:
from anthropic import AnthropicBedrock
client = AnthropicBedrock(aws_region="us-east-1")
with client.messages.stream(
model="anthropic.claude-sonnet-4-6-20250514-v1:0",
max_tokens=1024,
messages=[
{"role": "user", "content": "Write a short story about space"}
]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)TypeScript:
const client = new AnthropicBedrock({
awsRegion: "us-east-1",
});
const stream = await client.messages.stream({
model: "anthropic.claude-sonnet-4-6-20250514-v1:0",
max_tokens: 1024,
messages: [
{ role: "user", content: "Write a short story about space" }
],
});
for await (const event of stream) {
if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
process.stdout.write(event.delta.text);
}
}Full Example: Chat Application via Bedrock
Here is a complete chat application using Claude through Bedrock:
Python:
from anthropic import AnthropicBedrock
client = AnthropicBedrock(aws_region="us-east-1")
conversation_history = []
def chat(user_message):
conversation_history.append({
"role": "user",
"content": user_message
})
response = client.messages.create(
model="anthropic.claude-sonnet-4-6-20250514-v1:0",
max_tokens=2048,
system="You are a helpful and concise assistant.",
messages=conversation_history
)
assistant_message = response.content[0].text
conversation_history.append({
"role": "assistant",
"content": assistant_message
})
return assistant_message
# Usage
print(chat("What is Amazon Bedrock?"))
print(chat("What are its main advantages?"))
print(chat("How does it differ from the direct API?"))TypeScript:
const client = new AnthropicBedrock({
awsRegion: "us-east-1",
});
interface Message {
role: "user" | "assistant";
content: string;
}
const conversationHistory: Message[] = [];
async function chat(userMessage: string): Promise<string> {
conversationHistory.push({
role: "user",
content: userMessage,
});
const response = await client.messages.create({
model: "anthropic.claude-sonnet-4-6-20250514-v1:0",
max_tokens: 2048,
system: "You are a helpful and concise assistant.",
messages: conversationHistory,
});
const assistantMessage = response.content[0].type === "text"
? response.content[0].text
: "";
conversationHistory.push({
role: "assistant",
content: assistantMessage,
});
return assistantMessage;
}
// Usage
const answer1 = await chat("What is Amazon Bedrock?");
console.log(answer1);
const answer2 = await chat("What are its main advantages?");
console.log(answer2);When to Use Bedrock vs Direct API
| Scenario | Best Choice |
|---|---|
| Your infrastructure is fully on AWS | Bedrock |
| You need HIPAA/SOC2 compliance | Bedrock |
| You want the latest features immediately | Direct API |
| Small project or learning | Direct API |
| You want a single AWS bill | Bedrock |
| You need a private VPC | Bedrock |
| You want to switch between different models | Bedrock (supports multiple providers) |
Key Takeaways
- Start with the closest region — pick the AWS region nearest to your users
- Use IAM Roles — never use static access keys in production
- Enable CloudWatch — monitor your usage and response times
- Use Cross-Region — for applications that need high availability
- Check availability — not all models and features are available in every region
Next up: We will explore how to use Claude through Google Cloud Vertex AI as another enterprise deployment option.