- An AWS account with Bedrock access
- AWS credentials configured (SSO, env vars, or instance profile)
- Claude Code installed (
npm install -g @anthropic-ai/claude-code)
Verify Anthropic models are available and authorized:
# List available Claude models
aws bedrock list-foundation-models --region us-west-2 \
--query 'modelSummaries[?contains(providerName,`Anthropic`)].[modelId,modelName]' \
--output table
# Check authorization for a specific model
aws bedrock get-foundation-model-availability \
--model-id anthropic.claude-opus-4-8 --region us-west-2
# List inference profiles (required for invocation)
aws bedrock list-inference-profiles --region us-west-2 \
--query 'inferenceProfileSummaries[?contains(inferenceProfileId,`anthropic`)].[inferenceProfileId,status]' \
--output tableYou need authorizationStatus: AUTHORIZED and entitlementAvailability: AVAILABLE.
| Profile ID | Model |
|---|---|
us.anthropic.claude-opus-4-8 |
Claude Opus 4.8 (latest) |
us.anthropic.claude-opus-4-7 |
Claude Opus 4.7 |
us.anthropic.claude-opus-4-6-v1 |
Claude Opus 4.6 |
us.anthropic.claude-sonnet-4-6 |
Claude Sonnet 4.6 |
us.anthropic.claude-sonnet-4-5-20250929-v1:0 |
Claude Sonnet 4.5 |
us.anthropic.claude-haiku-4-5-20251001-v1:0 |
Claude Haiku 4.5 |
Note: Bedrock requires inference profile IDs (e.g.
us.anthropic.claude-opus-4-8), not raw model IDs. Direct model invocation will fail with aValidationException.
Set these environment variables:
# Required — tells Claude Code to use Bedrock
export CLAUDE_CODE_USE_BEDROCK=1
export AWS_REGION=us-west-2
# Optional — choose a model (defaults to Sonnet)
export ANTHROPIC_MODEL=us.anthropic.claude-opus-4-8Then run claude as normal. It will use your AWS credentials instead of an Anthropic API key.
# Add to ~/.zshenv, ~/.zshrc, or ~/.bashrc
cat >> ~/.zshenv << 'EOF'
export CLAUDE_CODE_USE_BEDROCK=1
export AWS_REGION=us-west-2
export ANTHROPIC_MODEL=us.anthropic.claude-opus-4-8
EOFClaude Code uses the standard AWS credential chain. Any of these work:
If your EC2 instance has an IAM role with bedrock:InvokeModel* permissions, it works automatically — no extra config needed.
aws sso login --profile default
claudeexport AWS_ACCESS_KEY_ID=AKIA...
export AWS_SECRET_ACCESS_KEY=...
claudeYour IAM role/user needs at minimum:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": "arn:aws:bedrock:*::foundation-model/anthropic.*"
}
]
}For inference profiles (cross-region), also add:
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": "arn:aws:bedrock:*:*:inference-profile/us.anthropic.*"
}Verify Bedrock invocation works before running Claude Code:
python3 -c "
import boto3, json
client = boto3.client('bedrock-runtime', region_name='us-west-2')
resp = client.invoke_model(
modelId='us.anthropic.claude-haiku-4-5-20251001-v1:0',
contentType='application/json',
accept='application/json',
body=json.dumps({
'anthropic_version': 'bedrock-2023-05-31',
'max_tokens': 32,
'messages': [{'role': 'user', 'content': 'say hi'}]
})
)
print(json.loads(resp['body'].read())['content'][0]['text'])
"| Problem | Fix |
|---|---|
ValidationException: Invocation of model ID ... with on-demand throughput isn't supported |
Use an inference profile ID (us.anthropic.claude-...) not a raw model ID |
AccessDeniedException |
Check IAM permissions — need bedrock:InvokeModel on the model/profile ARN |
Could not connect to the endpoint URL |
Wrong region — try us-west-2 or us-east-1 |
| Claude Code ignores Bedrock config | Make sure CLAUDE_CODE_USE_BEDROCK=1 is exported, not just set |