Skip to content

Instantly share code, notes, and snippets.

@ejc3
Created June 9, 2026 02:06
Show Gist options
  • Select an option

  • Save ejc3/5ee028c1c4b9b2ed8f3f2f2118c0c16b to your computer and use it in GitHub Desktop.

Select an option

Save ejc3/5ee028c1c4b9b2ed8f3f2f2118c0c16b to your computer and use it in GitHub Desktop.
Claude Code with Amazon Bedrock — setup & configuration

Using Claude Code with Amazon Bedrock

Prerequisites

  • 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)

Bedrock Status Check

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 table

You need authorizationStatus: AUTHORIZED and entitlementAvailability: AVAILABLE.

Available Inference Profiles (US)

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 a ValidationException.

Configuring Claude Code

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-8

Then run claude as normal. It will use your AWS credentials instead of an Anthropic API key.

Persist in shell config

# 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
EOF

Authentication Methods

Claude Code uses the standard AWS credential chain. Any of these work:

1. EC2 Instance Profile (recommended for dev servers)

If your EC2 instance has an IAM role with bedrock:InvokeModel* permissions, it works automatically — no extra config needed.

2. AWS SSO

aws sso login --profile default
claude

3. Environment Variables

export AWS_ACCESS_KEY_ID=AKIA...
export AWS_SECRET_ACCESS_KEY=...
claude

Required IAM Permissions

Your 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.*"
}

Quick Test

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'])
"

Troubleshooting

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment