HomeEnterprise & CloudClaude on Amazon Bedrock
intermediate12 min read· Module 11, Lesson 2

🟠Claude on Amazon Bedrock

Run Claude through AWS Bedrock — setup, IAM, and API differences

Claude on Amazon Bedrock

What is Amazon Bedrock?

Amazon Bedrock is a fully managed AWS service that gives you access to generative AI models from multiple providers — including Claude from Anthropic — through a unified API. Instead of calling Anthropic directly, you use Claude through AWS infrastructure.

Think of Bedrock as a "marketplace" for AI models inside AWS. You pick the model you want, and AWS handles everything else — infrastructure, scaling, and security.

Why Use Claude Through Bedrock?

There are compelling reasons why organizations prefer Bedrock over calling Anthropic directly:

BenefitExplanation
Data stays in AWSYour data never leaves the AWS environment — critical for compliance and privacy
Single billPay for everything on your existing AWS invoice — no separate Anthropic account needed
ComplianceBedrock supports HIPAA, SOC2, GDPR, and other compliance standards
AWS integrationIntegrates natively with Lambda, S3, CloudWatch, IAM
Private VPCRun everything inside your private network via PrivateLink
Access controlUse your existing IAM policies to manage who can call Claude

Enabling Claude Models in Bedrock Console

Before you can use Claude through Bedrock, you need to enable model access in your account:

  1. Open the AWS Console
  2. Search for Amazon Bedrock
  3. Go to Model access from the sidebar
  4. Find Anthropic in the provider list
  5. Select the models you want to enable:
    • Claude Opus 4
    • Claude Sonnet 4
    • Claude Haiku (3.5)
  6. Click Request model access
  7. Wait for approval (usually instant for some models)

Note: Not all models are available in every AWS region. Check availability in your region before planning your architecture.

IAM Permissions Setup

To use Bedrock, you need proper IAM permissions. Here is a basic IAM policy:

JSON
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream" ], "Resource": "arn:aws:bedrock:*::foundation-model/anthropic.*" } ] }

This policy allows invoking Anthropic models only. To restrict further, you can specify the region and model:

JSON
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream" ], "Resource": "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-sonnet-4-6-20250514-v1:0" } ] }

For administrative access to manage models:

JSON
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "bedrock:ListFoundationModels", "bedrock:GetFoundationModel", "bedrock:ListModelAccessPermissions", "bedrock:PutModelAccessPermission" ], "Resource": "*" } ] }

Model IDs on Bedrock

Model names in Bedrock differ from the direct Anthropic API names:

Anthropic ModelBedrock Model ID
claude-opus-4-6-20250514anthropic.claude-opus-4-6-20250514-v1:0
claude-sonnet-4-6-20250514anthropic.claude-sonnet-4-6-20250514-v1:0
claude-haiku-3-5-20241022anthropic.claude-3-5-haiku-20241022-v1:0

Important: Always use the full Bedrock model ID when invoking a model. Do not use the short Anthropic names.

Using the Anthropic SDK with Bedrock

The easiest way to use Claude on Bedrock is through the official Anthropic SDK with Bedrock configuration.

Installation — Python:

Terminal
pip install anthropic[bedrock]

Installation — TypeScript:

Terminal
npm install @anthropic-ai/sdk @anthropic-ai/bedrock-sdk

Python Example:

Python
from anthropic import AnthropicBedrock client = AnthropicBedrock( aws_region="us-east-1", ) message = client.messages.create( model="anthropic.claude-sonnet-4-6-20250514-v1:0", max_tokens=1024, messages=[ {"role": "user", "content": "What is the capital of France?"} ] ) print(message.content[0].text)

TypeScript Example:

TypeScript
const client = new AnthropicBedrock({ awsRegion: "us-east-1", }); const message = await client.messages.create({ model: "anthropic.claude-sonnet-4-6-20250514-v1:0", max_tokens: 1024, messages: [ { role: "user", content: "What is the capital of France?" } ], }); console.log(message.content[0].text);

Configuring Credentials

The SDK automatically picks up AWS credentials from multiple sources in the following order:

  1. Environment variables:
Terminal
export AWS_ACCESS_KEY_ID="your-access-key" export AWS_SECRET_ACCESS_KEY="your-secret-key" export AWS_REGION="us-east-1"
  1. AWS credentials file:
Terminal
aws configure
  1. IAM Role (on EC2, Lambda, or ECS) — the recommended approach for production

  2. Passed directly in code:

Python
client = AnthropicBedrock( aws_access_key="AKIAIOSFODNN7EXAMPLE", aws_secret_key="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", aws_region="us-east-1", )

Warning: Never hardcode access keys in production code. Use IAM Roles or AWS Secrets Manager instead.

API Differences: Bedrock vs Direct Anthropic API

While the Anthropic SDK unifies much of the interface, there are key differences:

AspectDirect Anthropic APIAmazon Bedrock
AuthenticationAPI keyAWS credentials (IAM)
Model IDsclaude-sonnet-4-6-20250514anthropic.claude-sonnet-4-6-20250514-v1:0
Endpointapi.anthropic.combedrock-runtime.{region}.amazonaws.com
BillingAnthropic invoiceAWS invoice
Rate limitsBased on Anthropic planBased on AWS quotas
Model availabilityAll modelsDepends on region
New featuresAvailable immediatelyMay have a short delay

Regional vs Global Endpoints

In Bedrock, each AWS region has its own endpoint:

bedrock-runtime.us-east-1.amazonaws.com bedrock-runtime.us-west-2.amazonaws.com bedrock-runtime.eu-west-1.amazonaws.com bedrock-runtime.ap-northeast-1.amazonaws.com

Considerations for choosing a region:

  • Closest geographically = lowest latency
  • Model availability — not all models are available in every region
  • Compliance requirements — some data must stay in specific regions (e.g., GDPR requires EU)
  • Capacity — some regions have higher throughput than others

Cross-Region Inference

The Cross-Region Inference feature allows Bedrock to distribute requests across multiple regions automatically:

Python
# Using a Cross-Region Inference Profile client = AnthropicBedrock( aws_region="us-east-1", ) message = client.messages.create( model="us.anthropic.claude-sonnet-4-6-20250514-v1:0", max_tokens=1024, messages=[ {"role": "user", "content": "Explain quantum computing"} ] )

Notice the us. prefix on the model ID — this activates Cross-Region Inference across US regions.

Benefits of Cross-Region Inference:

  • Higher availability — if one region is busy, the request routes to another
  • Greater throughput — leverage capacity across multiple regions
  • Fully transparent — no code changes needed (just change the model ID)

Pricing Differences

Pricing on Bedrock is similar to the direct API but has its own structure:

ModelInput Price (Anthropic)Input Price (Bedrock)
Claude Sonnet 4$3 / million tokens$3 / million tokens
Claude Opus 4$15 / million tokens$15 / million tokens
Claude Haiku 3.5$0.80 / million tokens$0.80 / million tokens

Note: Prices are subject to change. Always check the AWS Bedrock pricing page and Anthropic pricing page for current rates.

Pricing options on Bedrock:

  1. On-Demand — pay only for what you use with no commitments
  2. Provisioned Throughput — reserve a fixed capacity at a lower per-token price
  3. Commitment pricing — discounts for long-term commitments

Streaming Responses on Bedrock

Bedrock supports response streaming just like the direct API:

Python:

Python
from anthropic import AnthropicBedrock client = AnthropicBedrock(aws_region="us-east-1") with client.messages.stream( model="anthropic.claude-sonnet-4-6-20250514-v1:0", max_tokens=1024, messages=[ {"role": "user", "content": "Write a short story about space"} ] ) as stream: for text in stream.text_stream: print(text, end="", flush=True)

TypeScript:

TypeScript
const client = new AnthropicBedrock({ awsRegion: "us-east-1", }); const stream = await client.messages.stream({ model: "anthropic.claude-sonnet-4-6-20250514-v1:0", max_tokens: 1024, messages: [ { role: "user", content: "Write a short story about space" } ], }); for await (const event of stream) { if (event.type === "content_block_delta" && event.delta.type === "text_delta") { process.stdout.write(event.delta.text); } }

Full Example: Chat Application via Bedrock

Here is a complete chat application using Claude through Bedrock:

Python:

Python
from anthropic import AnthropicBedrock client = AnthropicBedrock(aws_region="us-east-1") conversation_history = [] def chat(user_message): conversation_history.append({ "role": "user", "content": user_message }) response = client.messages.create( model="anthropic.claude-sonnet-4-6-20250514-v1:0", max_tokens=2048, system="You are a helpful and concise assistant.", messages=conversation_history ) assistant_message = response.content[0].text conversation_history.append({ "role": "assistant", "content": assistant_message }) return assistant_message # Usage print(chat("What is Amazon Bedrock?")) print(chat("What are its main advantages?")) print(chat("How does it differ from the direct API?"))

TypeScript:

TypeScript
const client = new AnthropicBedrock({ awsRegion: "us-east-1", }); interface Message { role: "user" | "assistant"; content: string; } const conversationHistory: Message[] = []; async function chat(userMessage: string): Promise<string> { conversationHistory.push({ role: "user", content: userMessage, }); const response = await client.messages.create({ model: "anthropic.claude-sonnet-4-6-20250514-v1:0", max_tokens: 2048, system: "You are a helpful and concise assistant.", messages: conversationHistory, }); const assistantMessage = response.content[0].type === "text" ? response.content[0].text : ""; conversationHistory.push({ role: "assistant", content: assistantMessage, }); return assistantMessage; } // Usage const answer1 = await chat("What is Amazon Bedrock?"); console.log(answer1); const answer2 = await chat("What are its main advantages?"); console.log(answer2);

When to Use Bedrock vs Direct API

ScenarioBest Choice
Your infrastructure is fully on AWSBedrock
You need HIPAA/SOC2 complianceBedrock
You want the latest features immediatelyDirect API
Small project or learningDirect API
You want a single AWS billBedrock
You need a private VPCBedrock
You want to switch between different modelsBedrock (supports multiple providers)

Key Takeaways

  1. Start with the closest region — pick the AWS region nearest to your users
  2. Use IAM Roles — never use static access keys in production
  3. Enable CloudWatch — monitor your usage and response times
  4. Use Cross-Region — for applications that need high availability
  5. Check availability — not all models and features are available in every region

Next up: We will explore how to use Claude through Google Cloud Vertex AI as another enterprise deployment option.