Back to all articles
7 MIN READ

Claude on Amazon Bedrock: AWS Integration Guide

By Learnia Team

Claude on Amazon Bedrock: AWS Integration Guide

📅 Last updated: March 10, 2026 — Covers Bedrock with Claude Opus 4.6, Sonnet 4, and Haiku 3.5.

🔗 Pillar article: Claude API: Complete Guide


Why Claude on Bedrock?

If your infrastructure is already on AWS, Bedrock is the most natural way to integrate Claude. Here are the advantages:

AdvantageDescription
Unified billingClaude appears on your existing AWS bill
Native IAMGranular access control (who can use which model)
VPCRequests stay within your private network
ComplianceSOC 2, HIPAA, FedRAMP, ISO 27001
GuardrailsIntegrated and configurable content filtering
No API key managementUses standard AWS credentials
CloudWatchMonitoring and alerts on usage

Setup: Step by Step

1. Enable Model Access

In the AWS console:

  1. Navigate to Amazon Bedrock > Model access
  2. Click Manage model access
  3. Select the Anthropic models (Claude Opus, Sonnet, Haiku)
  4. Submit the request (approval is usually instantaneous)

2. Configure IAM

{
  "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-20250514-v1:0",
        "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-opus-4-20250918-v1:0"
      ]
    }
  ]
}

IAM best practices:

  • Use the principle of least privilege (one model per role)
  • Create specific roles per application
  • Add conditions (source IP, access hours)
  • Enable CloudTrail for auditing

3. Install the SDK

pip install boto3 anthropic[bedrock]

Code Examples

Basic Call with boto3

import boto3
import json

# Bedrock Runtime client
client = boto3.client(
    service_name="bedrock-runtime",
    region_name="us-east-1"
)

# Claude request
body = json.dumps({
    "anthropic_version": "bedrock-2023-05-31",
    "max_tokens": 1024,
    "messages": [
        {
            "role": "user",
            "content": "Explain the benefits of infrastructure as code."
        }
    ]
})

response = client.invoke_model(
    modelId="anthropic.claude-sonnet-4-20250514-v1:0",
    contentType="application/json",
    accept="application/json",
    body=body
)

result = json.loads(response["body"].read())
print(result["content"][0]["text"])
import anthropic

# Automatically uses AWS credentials
client = anthropic.AnthropicBedrock(
    aws_region="us-east-1"
)

message = client.messages.create(
    model="anthropic.claude-sonnet-4-20250514-v1:0",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "What are the AWS services for machine learning?"}
    ]
)

print(message.content[0].text)

Streaming

import anthropic

client = anthropic.AnthropicBedrock(aws_region="us-east-1")

with client.messages.stream(
    model="anthropic.claude-sonnet-4-20250514-v1:0",
    max_tokens=2048,
    messages=[{"role": "user", "content": "Write a microservices migration guide."}]
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

Bedrock vs Direct API Pricing

ModelBedrock InputBedrock OutputDirect API InputDirect API Output
Claude Opus 4.6$15.00/M$75.00/M$15.00/M$75.00/M
Claude Sonnet 4$3.00/M$15.00/M$3.00/M$15.00/M
Claude Haiku 3.5$0.80/M$4.00/M$0.80/M$4.00/M

Bedrock cost reduction options:

  • Provisioned Throughput: Guaranteed throughput, reduced pricing for high volumes
  • Batch Inference: Batch processing with 50% reduction
  • Cross-Region Inference: Automatic region optimization

Bedrock Guardrails

Bedrock guardrails add a configurable security layer around Claude.

# Call with guardrails
response = client.invoke_model(
    modelId="anthropic.claude-sonnet-4-20250514-v1:0",
    contentType="application/json",
    accept="application/json",
    body=body,
    guardrailIdentifier="my-guardrail-id",
    guardrailVersion="1"
)
Guardrail FeatureDescription
Content filtersBlock inappropriate content
Denied topicsForbid specific topics
Word filtersBlock specific words or phrases
Sensitive info filtersMask PII (names, emails, phone numbers)
Contextual groundingReduce hallucinations with sources

Enterprise Architecture

Typical Architecture

Loading diagram…

Lambda + Claude

import json
import boto3

bedrock = boto3.client("bedrock-runtime")

def lambda_handler(event, context):
    """Lambda function calling Claude via Bedrock."""
    user_question = event.get("question", "")
    
    body = json.dumps({
        "anthropic_version": "bedrock-2023-05-31",
        "max_tokens": 1024,
        "messages": [{"role": "user", "content": user_question}]
    })
    
    response = bedrock.invoke_model(
        modelId="anthropic.claude-sonnet-4-20250514-v1:0",
        body=body
    )
    
    result = json.loads(response["body"].read())
    
    return {
        "statusCode": 200,
        "body": json.dumps({
            "answer": result["content"][0]["text"],
            "tokens_used": result["usage"]
        })
    }

Monitoring with CloudWatch

import boto3

cloudwatch = boto3.client("cloudwatch")

# Create an alarm on invocation count
cloudwatch.put_metric_alarm(
    AlarmName="bedrock-claude-high-usage",
    MetricName="Invocations",
    Namespace="AWS/Bedrock",
    Statistic="Sum",
    Period=3600,
    Threshold=10000,
    ComparisonOperator="GreaterThanThreshold",
    EvaluationPeriods=1,
    AlarmActions=["arn:aws:sns:us-east-1:123456:alerts"],
    Dimensions=[{
        "Name": "ModelId",
        "Value": "anthropic.claude-sonnet-4-20250514-v1:0"
    }]
)

Available Metrics

MetricDescription
InvocationsNumber of model calls
InvocationLatencyLatency per request (ms)
InputTokenCountInput tokens consumed
OutputTokenCountOutput tokens generated
InvocationErrorsNumber of errors (4xx, 5xx)

Migrating from the Direct API

If you're already using the direct Anthropic API, migration to Bedrock is straightforward:

ChangeDirect APIBedrock
Clientanthropic.Anthropic()anthropic.AnthropicBedrock()
AuthAPI keyAWS credentials (IAM)
Model IDclaude-sonnet-4-20250514anthropic.claude-sonnet-4-20250514-v1:0
Endpointapi.anthropic.combedrock-runtime.{region}.amazonaws.com
Rest of codeIdenticalIdentical
# Before (Direct API)
# client = anthropic.Anthropic(api_key="sk-ant-...")
# model = "claude-sonnet-4-20250514"

# After (Bedrock)
client = anthropic.AnthropicBedrock(aws_region="us-east-1")
model = "anthropic.claude-sonnet-4-20250514-v1:0"

# The rest of the code is identical
message = client.messages.create(
    model=model,
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}]
)

GO DEEPER — FREE GUIDE

Module 0 — Prompting Fundamentals

Build your first effective prompts from scratch with hands-on exercises.

Newsletter

Weekly AI Insights

Tools, techniques & news — curated for AI practitioners. Free, no spam.

Free, no spam. Unsubscribe anytime.

FAQ

What is Amazon Bedrock?+

Amazon Bedrock is an AWS service that provides access to foundational AI models (including Claude) via a unified API. It natively integrates with the AWS ecosystem (IAM, VPC, CloudWatch, S3).

Why use Claude via Bedrock instead of the direct API?+

Bedrock offers consolidated AWS billing, enterprise compliance (SOC2, HIPAA, FedRAMP), VPC integration for network security, native guardrails, and fine-grained IAM permission management.

How do I access Claude on Bedrock?+

Enable the Claude model in the Bedrock console (Model Access), configure IAM roles with bedrock:InvokeModel permissions, and use the boto3 SDK or your preferred AWS SDK.

Is Bedrock more expensive than the direct Anthropic API?+

Prices on Bedrock are generally similar or slightly higher than the direct API. However, Bedrock offers AWS billing options (Reserved Capacity, Savings Plans) that can reduce costs for high volumes.

What's the difference between AWS Bedrock and Claude's direct API?+

Bedrock offers unified AWS billing, built-in SOC2/HIPAA compliance, native guardrails, and compatibility with the AWS ecosystem (IAM, CloudWatch, S3). The direct API offers access to the latest features first, potentially lower prices, and simpler integration. Bedrock is recommended for enterprises already on AWS.