Example configuration for using Claude APIs via AWS Bedrock.
- Configure AWS credentials (if not already done):
aws configureEnter your AWS credentials:
AWS Access Key ID: your-access-key-id
AWS Secret Access Key: your-secret-access-key
Default region name: eu-west-1
Default output format: json
- Copy the example environment file:
cp .env.example .env-
Edit
.envwith your AWS configuration -
Load environment variables:
export $(cat .env | grep -v '^#' | xargs)- Install Python dependencies:
uv venv
uv pip install boto3 python-dotenv- Run the example:
uv run python bedrock_example.py "Your prompt here"| Variable | Description | Example |
|---|---|---|
AWS_REGION |
AWS region for Bedrock | eu-west-1 |
ANTHROPIC_MODEL |
Claude model ID | anthropic.claude-3-haiku-20240307-v1:0 |
AWS_PROFILE |
AWS profile name (optional) | default |
# Basic query
uv run python bedrock_example.py "List 3 AWS services"
# Technical question
uv run python bedrock_example.py "Explain what Bedrock is"
# Code help
uv run python bedrock_example.py "Write a Python function to reverse a string"Credentials not found:
- Check AWS credentials:
aws configure list - Verify env vars are loaded:
echo $AWS_REGION
Model not available:
- Verify Bedrock is enabled in your AWS region
- Check model access in AWS Console > Bedrock > Model access
Permission denied:
- Ensure IAM permissions include
bedrock:InvokeModel