Claude on Amazon Bedrock: AWS Integration Guide
By Learnia Team
Claude on Amazon Bedrock: AWS Integration Guide
📅 Last updated: March 10, 2026 — Covers Bedrock with Claude Opus 4.6, Sonnet 4, and Haiku 3.5.
🔗 Pillar article: Claude API: Complete Guide
Why Claude on Bedrock?
If your infrastructure is already on AWS, Bedrock is the most natural way to integrate Claude. Here are the advantages:
| Advantage | Description |
|---|---|
| Unified billing | Claude appears on your existing AWS bill |
| Native IAM | Granular access control (who can use which model) |
| VPC | Requests stay within your private network |
| Compliance | SOC 2, HIPAA, FedRAMP, ISO 27001 |
| Guardrails | Integrated and configurable content filtering |
| No API key management | Uses standard AWS credentials |
| CloudWatch | Monitoring and alerts on usage |
Setup: Step by Step
1. Enable Model Access
In the AWS console:
- →Navigate to Amazon Bedrock > Model access
- →Click Manage model access
- →Select the Anthropic models (Claude Opus, Sonnet, Haiku)
- →Submit the request (approval is usually instantaneous)
2. Configure IAM
{
"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-20250514-v1:0",
"arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-opus-4-20250918-v1:0"
]
}
]
}
IAM best practices:
- →Use the principle of least privilege (one model per role)
- →Create specific roles per application
- →Add conditions (source IP, access hours)
- →Enable CloudTrail for auditing
3. Install the SDK
pip install boto3 anthropic[bedrock]
Code Examples
Basic Call with boto3
import boto3
import json
# Bedrock Runtime client
client = boto3.client(
service_name="bedrock-runtime",
region_name="us-east-1"
)
# Claude request
body = json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Explain the benefits of infrastructure as code."
}
]
})
response = client.invoke_model(
modelId="anthropic.claude-sonnet-4-20250514-v1:0",
contentType="application/json",
accept="application/json",
body=body
)
result = json.loads(response["body"].read())
print(result["content"][0]["text"])
With the Anthropic SDK (Recommended)
import anthropic
# Automatically uses AWS credentials
client = anthropic.AnthropicBedrock(
aws_region="us-east-1"
)
message = client.messages.create(
model="anthropic.claude-sonnet-4-20250514-v1:0",
max_tokens=1024,
messages=[
{"role": "user", "content": "What are the AWS services for machine learning?"}
]
)
print(message.content[0].text)
Streaming
import anthropic
client = anthropic.AnthropicBedrock(aws_region="us-east-1")
with client.messages.stream(
model="anthropic.claude-sonnet-4-20250514-v1:0",
max_tokens=2048,
messages=[{"role": "user", "content": "Write a microservices migration guide."}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
Bedrock vs Direct API Pricing
| Model | Bedrock Input | Bedrock Output | Direct API Input | Direct API Output |
|---|---|---|---|---|
| Claude Opus 4.6 | $15.00/M | $75.00/M | $15.00/M | $75.00/M |
| Claude Sonnet 4 | $3.00/M | $15.00/M | $3.00/M | $15.00/M |
| Claude Haiku 3.5 | $0.80/M | $4.00/M | $0.80/M | $4.00/M |
Bedrock cost reduction options:
- →Provisioned Throughput: Guaranteed throughput, reduced pricing for high volumes
- →Batch Inference: Batch processing with 50% reduction
- →Cross-Region Inference: Automatic region optimization
Bedrock Guardrails
Bedrock guardrails add a configurable security layer around Claude.
# Call with guardrails
response = client.invoke_model(
modelId="anthropic.claude-sonnet-4-20250514-v1:0",
contentType="application/json",
accept="application/json",
body=body,
guardrailIdentifier="my-guardrail-id",
guardrailVersion="1"
)
| Guardrail Feature | Description |
|---|---|
| Content filters | Block inappropriate content |
| Denied topics | Forbid specific topics |
| Word filters | Block specific words or phrases |
| Sensitive info filters | Mask PII (names, emails, phone numbers) |
| Contextual grounding | Reduce hallucinations with sources |
Enterprise Architecture
Typical Architecture
Lambda + Claude
import json
import boto3
bedrock = boto3.client("bedrock-runtime")
def lambda_handler(event, context):
"""Lambda function calling Claude via Bedrock."""
user_question = event.get("question", "")
body = json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 1024,
"messages": [{"role": "user", "content": user_question}]
})
response = bedrock.invoke_model(
modelId="anthropic.claude-sonnet-4-20250514-v1:0",
body=body
)
result = json.loads(response["body"].read())
return {
"statusCode": 200,
"body": json.dumps({
"answer": result["content"][0]["text"],
"tokens_used": result["usage"]
})
}
Monitoring with CloudWatch
import boto3
cloudwatch = boto3.client("cloudwatch")
# Create an alarm on invocation count
cloudwatch.put_metric_alarm(
AlarmName="bedrock-claude-high-usage",
MetricName="Invocations",
Namespace="AWS/Bedrock",
Statistic="Sum",
Period=3600,
Threshold=10000,
ComparisonOperator="GreaterThanThreshold",
EvaluationPeriods=1,
AlarmActions=["arn:aws:sns:us-east-1:123456:alerts"],
Dimensions=[{
"Name": "ModelId",
"Value": "anthropic.claude-sonnet-4-20250514-v1:0"
}]
)
Available Metrics
| Metric | Description |
|---|---|
Invocations | Number of model calls |
InvocationLatency | Latency per request (ms) |
InputTokenCount | Input tokens consumed |
OutputTokenCount | Output tokens generated |
InvocationErrors | Number of errors (4xx, 5xx) |
Migrating from the Direct API
If you're already using the direct Anthropic API, migration to Bedrock is straightforward:
| Change | Direct API | Bedrock |
|---|---|---|
| Client | anthropic.Anthropic() | anthropic.AnthropicBedrock() |
| Auth | API key | AWS credentials (IAM) |
| Model ID | claude-sonnet-4-20250514 | anthropic.claude-sonnet-4-20250514-v1:0 |
| Endpoint | api.anthropic.com | bedrock-runtime.{region}.amazonaws.com |
| Rest of code | Identical | Identical |
# Before (Direct API)
# client = anthropic.Anthropic(api_key="sk-ant-...")
# model = "claude-sonnet-4-20250514"
# After (Bedrock)
client = anthropic.AnthropicBedrock(aws_region="us-east-1")
model = "anthropic.claude-sonnet-4-20250514-v1:0"
# The rest of the code is identical
message = client.messages.create(
model=model,
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}]
)
Module 0 — Prompting Fundamentals
Build your first effective prompts from scratch with hands-on exercises.
Weekly AI Insights
Tools, techniques & news — curated for AI practitioners. Free, no spam.
Free, no spam. Unsubscribe anytime.
→Related Articles
FAQ
What is Amazon Bedrock?+
Amazon Bedrock is an AWS service that provides access to foundational AI models (including Claude) via a unified API. It natively integrates with the AWS ecosystem (IAM, VPC, CloudWatch, S3).
Why use Claude via Bedrock instead of the direct API?+
Bedrock offers consolidated AWS billing, enterprise compliance (SOC2, HIPAA, FedRAMP), VPC integration for network security, native guardrails, and fine-grained IAM permission management.
How do I access Claude on Bedrock?+
Enable the Claude model in the Bedrock console (Model Access), configure IAM roles with bedrock:InvokeModel permissions, and use the boto3 SDK or your preferred AWS SDK.
Is Bedrock more expensive than the direct Anthropic API?+
Prices on Bedrock are generally similar or slightly higher than the direct API. However, Bedrock offers AWS billing options (Reserved Capacity, Savings Plans) that can reduce costs for high volumes.
What's the difference between AWS Bedrock and Claude's direct API?+
Bedrock offers unified AWS billing, built-in SOC2/HIPAA compliance, native guardrails, and compatibility with the AWS ecosystem (IAM, CloudWatch, S3). The direct API offers access to the latest features first, potentially lower prices, and simpler integration. Bedrock is recommended for enterprises already on AWS.