⚠️ Model IDs change frequently: The model IDs and configuration in this guide reflect the state at the time of writing. Anthropic regularly releases new Claude versions on Bedrock. Always check the AWS Bedrock supported models documentation and Bedrock model IDs reference for the most current model identifiers and regional availability.
Claude Code is a powerful CLI tool that allows you to interact with Claude AI models directly from your terminal. This guide will walk you through setting up Claude Code to work with Amazon Bedrock as the backend provider.
What is Claude Code?#
Claude Code is a powerful CLI tool that brings Claude’s AI capabilities to your terminal. It provides an interactive coding assistant that understands your local files and can help with various software engineering tasks.
Check out this video for a quick overview of Claude Code in action:
Prerequisites#
- AWS account with Bedrock access enabled
- Node.js (v14 or later) and npm installed on your system
- AWS CLI installed and configured with appropriate permissions
- Access to Anthropic Claude models in your AWS Bedrock account (Claude Sonnet 4.5 recommended)
Setup Steps#
Install Claude Code CLI
Install the official Claude Code CLI tool from Anthropic:
npm install -g @anthropic-ai/claude-codeYou can verify the installation was successful by running:
claude --versionFor detailed installation instructions, refer to the official Claude Code documentation.
Configure AWS Credentials
Ensure your AWS credentials are properly configured with permissions for Bedrock:
aws configureYou’ll need to enter:
- AWS Access Key ID
- AWS Secret Access Key
- Default region name (use a region where Claude models are available, like
us-east-1) - Default output format (recommended:
json)
For IAM permissions, your user/role needs:
bedrock:InvokeModelbedrock:InvokeModelWithResponseStreambedrock:ListFoundationModelsbedrock:ListInferenceProfiles
For detailed AWS credentials setup, see the AWS CLI Configuration Guide.
Enable Claude Model Access in Bedrock
Navigate to the AWS Bedrock console in a supported region (e.g.,
us-east-1)Complete Bedrock onboarding if needed (accept terms and conditions)
Go to “Model access” → “Manage model access”
Find “Anthropic” and enable the Claude models you want to use:
- Claude Sonnet 4.5 (recommended) -
global.anthropic.claude-sonnet-4-5-20250929-v1:0 - Claude Opus 4.6 (most capable) - for complex reasoning and agentic tasks
- Claude Haiku 4.5 (fast/cheap) -
us.anthropic.claude-haiku-4-5-20251001-v1:0
- Claude Sonnet 4.5 (recommended) -
Click “Request model access” and “Save changes”
Wait a few minutes for access to be granted (status will change from “Pending” to “Access granted”)
You can verify access using the AWS CLI:
aws bedrock list-foundation-models --region us-east-1 | grep anthropic.claudeIf you encounter issues, check that your account has completed Bedrock onboarding and review service quotas in your selected region.
Set Environment Variables
To tell Claude Code to use Bedrock as its backend, you need to set some environment variables. These are special settings that tell the software which model to use and where to find it.
Quick Start (Temporary Use)#
If you just want to try Claude Code with Bedrock quickly, you can run these commands in your terminal before using Claude:
# Copy and paste these lines into your terminal export ANTHROPIC_MODEL='global.anthropic.claude-sonnet-4-5-20250929-v1:0' export CLAUDE_CODE_USE_BEDROCK=1After running these commands in your terminal window, you can immediately use Claude Code with Bedrock by running
claudecommands in that same terminal window. However, these settings will only last until you close that terminal window.For US East Region (Virginia)#
If you’re using the US East region (which is the default for many AWS accounts):
export AWS_REGION='us-east-1'Optional: Configure Haiku Model#
Claude Code uses a smaller/faster model for some operations. By default, it auto-selects the Haiku model, but you can manually specify it:
export ANTHROPIC_SMALL_FAST_MODEL='us.anthropic.claude-haiku-4-5-20251001-v1:0'For Permanent Configuration#
To avoid having to set these variables every time, you can make them permanent by adding them to your shell’s configuration file:
Open your shell configuration file in a text editor:
- For Mac/Linux with Bash:
nano ~/.bashrcornano ~/.bash_profile - For Mac with Zsh:
nano ~/.zshrc - For Fish shell:
nano ~/.config/fish/config.fish
- For Mac/Linux with Bash:
Add these lines at the end of the file:
# Claude Code Bedrock configuration export ANTHROPIC_MODEL='global.anthropic.claude-sonnet-4-5-20250929-v1:0' export CLAUDE_CODE_USE_BEDROCK=1 export AWS_REGION='us-east-1' # Change this if using a different region # Optional: explicitly set Haiku model version # export ANTHROPIC_SMALL_FAST_MODEL='us.anthropic.claude-haiku-4-5-20251001-v1:0'Save the file and exit the editor
- In nano: Press
Ctrl+Oto save, thenEnter, thenCtrl+Xto exit
- In nano: Press
Apply the changes by reloading your configuration:
# For bash (choose one depending on which file you edited) source ~/.bashrc # OR source ~/.bash_profile # For zsh source ~/.zshrc # For fish source ~/.config/fish/config.fish
After completing these steps, Claude Code will use Bedrock in all your terminal sessions.
Using Claude Code with Bedrock#
Claude Code has access to the directory where it’s executed, allowing it to analyze your project files, understand your codebase, and assist with development tasks. It guides you through complex processes by suggesting next steps and requesting permission before running commands that modify your files or system.
Once configured with Bedrock, you can start using Claude Code with commands like:
# Run Claude in interactive mode (most useful way to use Claude Code)
claude
# Ask Claude a question
claude "How do I optimize Docker images?"
# Run Claude with context from specific files
claude --context path/to/file.py "Explain this code"
# Multiple contexts for more comprehensive analysis
claude --context file1.js --context file2.js "How do these components interact?"Benefits of Using Bedrock Backend#
- Data privacy - your queries stay within your AWS environment
- Cost management through AWS billing
- Access control through IAM policies
- Lower latency (depending on region configuration)
- Integration with AWS Guardrails for content filtering
Alternative Authentication Methods#
Using AWS SSO#
If your organization uses AWS SSO, you can configure Claude Code to automatically refresh credentials:
Create or edit
~/.claude/settings.json:{ "awsAuthRefresh": "aws sso login --profile myprofile", "env": { "AWS_PROFILE": "myprofile" } }Claude Code will automatically detect expired credentials and run the refresh command.
Using Bedrock API Keys (Simplified Auth)#
For simpler setups without full AWS CLI configuration, you can use Bedrock API Keys:
export AWS_BEARER_TOKEN_BEDROCK=your-bedrock-api-key
export CLAUDE_CODE_USE_BEDROCK=1This eliminates the need for AWS CLI configuration and is ideal for developers who only need Bedrock access.
Enterprise Features#
AWS Guardrails Integration#
You can implement content filtering via Bedrock Guardrails by adding custom headers:
{
"env": {
"ANTHROPIC_CUSTOM_HEADERS": "X-Amzn-Bedrock-GuardrailIdentifier: your-guardrail-id\nX-Amzn-Bedrock-GuardrailVersion: 1"
}
}This is useful for compliance-focused organizations that need to filter or moderate AI responses.
Troubleshooting#
If you encounter issues with Claude Code using Bedrock, try these troubleshooting steps:
Connection and Authentication Issues#
Verify AWS Credentials and Permissions
# Check if your credentials are properly configured aws sts get-caller-identity # Verify you have Bedrock access aws bedrock list-foundation-models --region us-east-1Confirm Model Access
# Check if Claude Sonnet 4.5 is available to your account aws bedrock list-foundation-models --query "modelSummaries[?contains(modelId, 'claude')]" --region us-east-1Region Configuration
- Ensure your
AWS_REGIONenvironment variable (or default region) is set to a region where Claude models are available - Verify model availability in your region in the Bedrock service endpoints documentation
- Ensure your
Common Error Messages#
“AccessDeniedException” - Check IAM permissions; your user/role needs
bedrock:InvokeModelpermission“ValidationException: Model not found” - Verify model ID and region compatibility
“ResourceNotFoundException” - Ensure you’ve completed model access approval
“ThrottlingException” or “429 Too many tokens, please wait before trying again.” - You may have exceeded your quota or rate limit. When this happens, the Claude CLI will display a message saying “429 Too many tokens, please wait before trying again.” This is because AWS Bedrock enforces rate limits on API requests to prevent abuse and ensure fair resource allocation across all users.
What’s happening: AWS Bedrock has token rate limits that restrict how many tokens you can process within a specific timeframe (usually per minute). When you exceed this limit, AWS returns a 429 error code (Too Many Requests), which Claude CLI then displays as a user-friendly message.
How to fix it:
- Wait a few minutes before trying again to allow your token quota to refresh
- For production applications, implement exponential backoff and retry logic
- If you consistently hit limits, request a quota increase through the AWS Service Quotas console
- Check your Bedrock quotas to understand your current limits
Environment Debugging#
Run Claude Code with debug logging enabled:
DEBUG=* claude "Your prompt here"For persistent issues, you can check AWS CloudTrail logs to see if your Bedrock API calls are being made and any errors they’re returning:
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=InvokeModelFor more comprehensive troubleshooting and documentation:
Meta: How This Post Was Created#
This post was originally created using Claude Code CLI in interactive mode, shortly after Claude Code’s initial release when there were no mature open-source alternatives. The initial content and featured image were generated entirely through AI-assisted conversation.
Since then, the post has been significantly refactored and updated to reflect the latest model versions and configuration options.
Author’s note: I have since migrated my AI coding workflow to OpenCode and AWS Kiro - both excellent alternatives that emerged after Claude Code’s launch. This post remains relevant for those who prefer or need to use Claude Code with Bedrock.
