OpenAI to AWS Bedrock: Enterprise Migration Guide
AWS Bedrock provides enterprise-grade AI with VPC isolation, SOC 2 compliance, and unified access to Claude, Llama, and Titan models. Essential for regulated industries.
Why Enterprise Teams Choose AWS Bedrock
When standard API access isn't sufficient due to compliance requirements, AWS Bedrock offers:
Typical use cases: Healthcare (HIPAA), Finance (SOC 2/PCI), Government (FedRAMP), Legal (data residency)
Found this guide useful?
Get weekly AI credit updates — new programs, price drops, migration tips. Free, always.
Using our affiliate links supports free access to all guides.
Available Models in Bedrock
Anthropic Claude:
Meta Llama:
Mistral:
Step 1: Enable Bedrock Access
Step 2: Install AWS SDK
pip install boto3 anthropic-bedrock
# or for direct Bedrock client:
pip install boto3
Set up credentials:
aws configure # or use IAM roles in productionStep 3: Migrate Your API Calls
BEFORE (Direct OpenAI):
from openai import OpenAI
client = OpenAI(api_key="sk-...")
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Analyze this contract for risks."}]
)AFTER (AWS Bedrock with Claude):
import boto3
import json
bedrock = boto3.client("bedrock-runtime", region_name="us-east-1")
body = json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 2048,
"messages": [{"role": "user", "content": "Analyze this contract for risks."}]
})
response = bedrock.invoke_model(
modelId="anthropic.claude-3-5-sonnet-20241022-v2:0",
body=body
)
result = json.loads(response["body"].read())
text = result["content"][0]["text"]Step 4: Set Up VPC Isolation
For maximum security, use Bedrock VPC endpoints:
In your Terraform/CloudFormation:
aws_vpc_endpoint:
service_name: com.amazonaws.us-east-1.bedrock-runtime
vpc_id: your-vpc-id
subnet_ids: [private-subnet-1, private-subnet-2]
security_group_ids: [bedrock-sg]With VPC endpoints, all Bedrock traffic stays within AWS network and never traverses the public internet.
Step 5: Streaming Responses
For real-time applications:
response = bedrock.invoke_model_with_response_stream(
modelId="anthropic.claude-3-5-sonnet-20241022-v2:0",
body=json.dumps(body)
)
for event in response["body"]:
chunk = json.loads(event["chunk"]["bytes"])
if chunk["type"] == "content_block_delta":
print(chunk["delta"]["text"], end="")Cost Considerations
Bedrock pricing is slightly higher than direct API access due to enterprise features:
Use AWS Cost Explorer to monitor Bedrock spending and set billing alerts.
Apply for AWS Activate Credits
AWS Activate for startups offers up to $100K in credits including Bedrock usage. If you're an enterprise, contact your AWS account manager about Bedrock Enterprise Discount Plans.