Skip to content

Killian-Jentic/bedrock-python-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude APIs with AWS Bedrock

Example configuration for using Claude APIs via AWS Bedrock.

Setup

  1. Configure AWS credentials (if not already done):
aws configure

Enter 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
  1. Copy the example environment file:
cp .env.example .env
  1. Edit .env with your AWS configuration

  2. Load environment variables:

export $(cat .env | grep -v '^#' | xargs)
  1. Install Python dependencies:
uv venv
uv pip install boto3 python-dotenv
  1. Run the example:
uv run python bedrock_example.py "Your prompt here"

Environment Variables

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

Usage Examples

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

Troubleshooting

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages