How to run Claude Code via AWS Bedrock instead of Anthropic's direct API. Covers IAM setup, environment variables, model IDs, and when to use Bedrock vs the Anthropic API.
AWS Bedrock lets you run Claude Code using Claude models hosted in your AWS account — traffic stays within AWS infrastructure, billing consolidates with your existing AWS costs, and you can apply IAM and VPC controls directly.
bedrock:InvokeModel permissionnpm install -g @anthropic-ai/claude-code{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": [
"arn:aws:bedrock:*::foundation-model/anthropic.claude-sonnet-4-6-v1:0",
"arn:aws:bedrock:*::foundation-model/anthropic.claude-haiku-4-5-20251001-v1:0",
"arn:aws:bedrock:*::foundation-model/anthropic.claude-opus-4-7-v1:0"
]
}
]
}
# Required: tell Claude Code to use Bedrock
export ANTHROPIC_BEDROCK=true
# Required: your AWS region (must match where you enabled the models)
export AWS_REGION=us-east-1
# Authentication — choose one:
# Option A: IAM role (recommended for EC2/ECS/Lambda)
# No env vars needed — Claude Code uses the instance's IAM role automatically
# Option B: named profile (~/.aws/credentials)
export AWS_PROFILE=my-bedrock-profile
# Option C: explicit access key (use only for local dev, never in CI)
export AWS_ACCESS_KEY_ID=AKIA...
export AWS_SECRET_ACCESS_KEY=...
# Optional: override the default model
export ANTHROPIC_MODEL=anthropic.claude-haiku-4-5-20251001-v1:0
Once set, start Claude Code normally: claude. All model calls route through Bedrock.
| Anthropic model | Bedrock model ID | Notes |
|---|---|---|
| claude-sonnet-4-6 | anthropic.claude-sonnet-4-6-v1:0 | Default for Claude Code — best balance |
| claude-haiku-4-5-20251001 | anthropic.claude-haiku-4-5-20251001-v1:0 | Fastest, lowest cost |
| claude-opus-4-7 | anthropic.claude-opus-4-7-v1:0 | Highest quality, most expensive |
Cross-region inference ARN format: arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-sonnet-4-6-v1:0
For air-gapped or fully private deployments, route Bedrock traffic through a VPC endpoint:
# Create the Bedrock VPC interface endpoint
aws ec2 create-vpc-endpoint --vpc-id vpc-0abc123 --vpc-endpoint-type Interface --service-name com.amazonaws.us-east-1.bedrock-runtime --subnet-ids subnet-0def456 --security-group-ids sg-0ghi789 --private-dns-enabled
# Claude Code picks up the private DNS automatically — no env var change needed
With a VPC endpoint, Claude Code traffic never traverses the public internet. Only port 443 outbound to the endpoint ENI is required.
| Scenario | Direct API | Bedrock | Bedrock advantage |
|---|---|---|---|
| Sonnet input (per 1M tokens) | $3.00 | $3.00 | None on list price |
| Enterprise volume discount | Negotiated with Anthropic | Included in AWS EDP | Leverage existing AWS spend |
| Billing consolidation | Separate Anthropic invoice | AWS invoice | Single vendor, cost tags |
| Compliance (HIPAA BAA) | Separate Anthropic BAA | Covered by AWS BAA | No additional contract |
# Error: "AccessDeniedException: is not authorized to perform: bedrock:InvokeModel"
# → The IAM role/user lacks bedrock:InvokeModel permission on the model ARN.
# Fix: attach the policy shown in the IAM section above.
# Error: "ValidationException: The requested model is not available"
# → Model not enabled in Bedrock console for this region.
# Fix: Bedrock console → Model access → Request access → Anthropic models.
# Error: "Could not find region"
# → AWS_REGION env var not set.
# Fix: export AWS_REGION=us-east-1
# Verify Bedrock is active:
claude --version # shows "Bedrock: us-east-1" in the header if configured correctly
For Enterprise team deployments routing through Bedrock, see Claude Code Enterprise. For running Claude Code in containerized environments on AWS ECS or Fargate, see Claude Code with Docker.