
Claude Code on Amazon Bedrock: Quick Setup Guide
Configure Anthropic's AI Coding Assistant with AWS Bedrock
Benefits of Using Claude Code with Amazon Bedrock
Setting up Claude Code with Amazon Bedrock
Important: Prompt Caching & Cost Management
Project Initialization with /init
Accepting and Reviewing Code Additions from Claude Code
Best Practices for Code Review
Managing Context with the /compact Command
Monitoring Your Costs with Claude Code
Additional Resources and Continued Learning
Building a Calculator Web App with Claude Code: A Step-by-Step Tutorial
- Edits files and fixes bugs across your codebase
- Answers questions about code architecture and logic
- Executes and fixes tests, resolves merge conflicts, and more
- Works directly from your terminal with your local environment
- Claude 3.7 Sonnet: The primary model that handles complex code understanding, generation, and reasoning tasks
- Claude 3.5 Haiku: A lightweight model used for specific functions within Claude Code:
- Faster response times for simpler queries
- More efficient token usage for routine operations
- Handling background tasks and file indexing
- Preprocessing and filtering code before sending to the more powerful Sonnet model
⚠️ IMPORTANT ⚠️: You must explicitly enable access to both Claude 3.7 Sonnet and Claude 3.5 Haiku models in your AWS Bedrock Model Access settings for the region you're using. Failure to enable either model will result in 403 Forbidden errors when using Claude Code. 🔑 🚫
See the AWS Bedrock Getting Started Guide for instructions on enabling model access.
- Superior code comprehension and generation capabilities
- Enhanced reasoning for debugging complex issues
- Improved context handling for navigating large codebases
- Better understanding of programming concepts and patterns
- Optimized for terminal-based interactions in Claude Code
- Leverage your existing AWS Bedrock allocation and billing
- Access to Claude 3.7 Sonnet's advanced coding capabilities
- Keep your code interactions within your AWS infrastructure
- Potentially access higher rate limits when properly configured
- Maintain consistent security and compliance standards
- Use prompt caching (if available) for cost optimization
- Operating Systems: macOS 10.15+, Ubuntu 20.04+/Debian 10+, or Windows via WSL
- Hardware: 4GB RAM minimum
- Software:
- Node.js 18+
- git 2.23+ (optional)
- GitHub or GitLab CLI for PR workflows (optional)
- ripgrep (rg) for enhanced file search (optional)
- Network: Internet connection required for authentication and AI processing
https://docs.aws.amazon.com/cli/v1/userguide/cli-chap-configure.html
- Using AWS CLI (easiest method):
- Run
aws configure
- Enter your access key, secret key, default region (ensure you have Bedrock access in that region), and set output to json.
- Manual Configuration:
- Create credential files in
~/.aws/credentials
and~/.aws/config
1
2
3
4
5
6
7
8
9
10
11
12
# Install Claude Code
npm install -g @anthropic-ai/claude-code
# Configure for Bedrock with Claude 3.7 Sonnet
export CLAUDE_CODE_USE_BEDROCK=1
export ANTHROPIC_MODEL='us.anthropic.claude-3-7-sonnet-20250219-v1:0'
# Control prompt caching - set to 1 to disable (see note below)
export DISABLE_PROMPT_CACHING=1
# Launch Claude Code
claude
- What it does: Significantly reduces token usage and costs by caching prompts
- Availability: Available to select Bedrock customers in preview (coming to Bedrock GA in the future)
- How to control: Use the
DISABLE_PROMPT_CACHING
environment variable:- To disable caching:
export DISABLE_PROMPT_CACHING=true
- To enable caching (if you have access):
unset DISABLE_PROMPT_CACHING
(remove the variable altogether)
- If you have access to prompt caching (preview or GA): Definitely use it! Just omit the
DISABLE_PROMPT_CACHING
variable. - If you don't have prompt caching: Be mindful of usage as costs can accumulate quickly.
- Monitor your usage with the
/cost
command within Claude Code - Consider using
/compact
and/clear
commands regularly to manage context size
/init
- Generates a comprehensive
CLAUDE.md
guide for your project - Creates documentation tailored to your specific codebase
- Helps new team members understand the project structure
- Provides a reference for working with Claude Code in your project
- Start Claude Code in your project directory with
claude
- Type
/init
in the interactive REPL - Claude will analyze your codebase and generate the guide
- Review the generated
CLAUDE.md
file - Optionally commit the file to your repository with
claude commit
- Claude Code uses a human in the loop permission system for safety
- File modifications require explicit approval by default
- You'll be prompted to confirm before changes are made
- Carefully examine suggested changes before approving them
- Understand what the code does - ask Claude to explain if needed
- Check for edge cases that might not have been considered
- Verify security implications of any code that handles sensitive data
- Test the changes after they're applied to ensure they work as expected
⚠️ IMPORTANT ⚠️: You should always use the Yes option and avoid using "Yes, don't ask again" to ensure that all code, file changes, and commands generated by Claude are strictly reviewed by a human. This human-in-the-loop review process is critical for maintaining security and code quality. 👁️ 🔒
/compact
command is a powerful tool for managing context and maintaining efficient conversations with Claude Code:- What it does: Summarizes your conversation history into a concise format
- Benefits: Preserves essential information while reducing token count
- When to use: After completing major tasks, when responses slow down, or before starting new subtasks
- Token savings: Significantly reduces token usage, helping manage costs even with prompt caching
/compact
regularly is a best practice for maintaining coherent and efficient interactions with Claude Code, especially for complex coding tasks that require extended conversations.- During a session: Use the
/cost
command to see current token usage and estimated costs - Session summary: View a cost summary automatically displayed when exiting Claude Code
- Set spend limits: Configure spending thresholds through your account settings
summarize this project
to test your setup. You can also generate a project guide with the /init
command.- Build a complete calculator web application from scratch
- Demonstrate Claude Code's capabilities for code generation and enhancement
- Show how to add scientific calculator functions to an existing project
- Explore best practices for working with AI coding assistants
- Provide practical examples of context management with
/compact
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.