The rest of this guide explains what you're paying for and how to build on it.
What Is AWS Bedrock?
Amazon Bedrock is a serverless service that provides:
- Foundation model access - Claude, Llama, Mistral, and more via API
- Fine-tuning capabilities - Customize models with your data
- RAG support - Connect models to your knowledge bases
- Agents - Build autonomous AI workflows
- Guardrails - Control model outputs for safety
Think of Bedrock as a "model marketplace with infrastructure"βyou choose which AI models to use, AWS handles scaling, security, and availability.
Why Use Bedrock Instead of Direct APIs?
You could use Anthropic's API directly, so why go through AWS?
| Factor | Direct API | AWS Bedrock |
|---|---|---|
| Billing | Separate vendor | Consolidated AWS billing |
| Data residency | Varies by provider and configuration | Depends on model and inference profile; review destination Regions |
| VPC integration | Requires configuration | PrivateLink available |
| IAM integration | API keys only | Native IAM policies |
| Multiple models | Multiple accounts/APIs | Single API, many models |
| Compliance | Depends on service and configuration | Depends on service eligibility and your configuration |
| Model switching | Depends on provider | Converse can simplify supported model changes |
Key benefit: If you're already on AWS and need enterprise controls (VPC, IAM, compliance), Bedrock simplifies integration significantly.
Available Foundation Models
Bedrock offers models from multiple providers. Availability and model versions change by Region; check the console before selecting one. The examples below illustrate provider categories rather than a current availability list:
Text Generation Models
| Provider | Model family | Best For |
|---|---|---|
| Anthropic | Claude | Reasoning and coding |
| Meta | Llama | Open-weight alternatives |
| Mistral | Mistral | Multilingual and coding tasks |
| Amazon | Nova and Titan | General text tasks |
| Cohere | Command | RAG applications |
Image Generation Models
| Provider | Model | Use Case |
|---|---|---|
| Stability AI | Image models | Image generation |
| Amazon | Titan Image Generator | Text-to-image, editing |
Embedding Models
| Provider | Model | Dimensions |
|---|---|---|
| Amazon | Titan Embeddings V2 | 1024 |
| Cohere | Embed | 1024 |
Bedrock Pricing Explained
Bedrock uses token-based pricingβyou pay per input and output token processed. Pricing varies significantly by model.
Text Model Pricing (per 1,000 tokens)
Input and output token rates vary by model, Region, and inference option. Check current AWS pricing for the model you select.
Example Cost Calculation
Multiply your expected input and output tokens by the corresponding current rates, then by request volume. Include any additional charges for features your application uses.
Provisioned Throughput
For predictable, high-volume workloads, compare available committed-capacity options with on-demand pricing. Availability, commitment terms, and pricing depend on the model and current AWS offering.
Getting Started: Your First Bedrock Call
Prerequisites
- AWS account with Bedrock available in your chosen Region
- Check the access steps for your selected model or inference profile
- IAM permissions for
bedrock:InvokeModel
Python Example with Boto3
Set BEDROCK_MODEL_ID to an available model or inference profile ID in your account before running these examples.
import boto3
import json
import os
# Create Bedrock runtime client
bedrock = boto3.client(
service_name='bedrock-runtime',
region_name='us-east-1'
)
# Prepare the request for Claude
body = json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Explain what AWS Bedrock is in 2 sentences."
}
]
})
# Invoke the model
response = bedrock.invoke_model(
modelId=os.environ["BEDROCK_MODEL_ID"],
contentType="application/json",
accept="application/json",
body=body
)
# Parse response
response_body = json.loads(response['body'].read())
print(response_body['content'][0]['text'])
Using the Converse API (Recommended)
The Converse API provides a unified interface across supported models:
import boto3
import os
bedrock = boto3.client('bedrock-runtime', region_name='us-east-1')
response = bedrock.converse(
modelId=os.environ["BEDROCK_MODEL_ID"],
messages=[
{
"role": "user",
"content": [{"text": "What is AWS Bedrock?"}]
}
],
inferenceConfig={
"maxTokens": 1024,
"temperature": 0.7
}
)
print(response['output']['message']['content'][0]['text'])
Benefit: Converse shares a message format across supported models, but switching may still require changes to parameters, inference profiles, or response handling.
Bedrock Knowledge Bases (RAG)
Knowledge Bases let you connect foundation models to your own data using Retrieval-Augmented Generation (RAG).
How It Works
A Knowledge Base turns a plain question into a grounded answer by retrieving your own documents before the model responds. The animated flow below traces a single query through the four stages Bedrock runs for you.
Supported Data Sources
- Amazon S3 (PDF, TXT, MD, HTML, DOC, CSV)
- Web crawlers
- Confluence
- Salesforce
- SharePoint
Creating a Knowledge Base
This example illustrates the required configuration shape. The sample ARNs and index names must be replaced with real resources before it can run.
import boto3
bedrock_agent = boto3.client('bedrock-agent', region_name='us-east-1')
# Create knowledge base
response = bedrock_agent.create_knowledge_base(
name='company-docs-kb',
roleArn='arn:aws:iam::123456789:role/BedrockKBRole',
knowledgeBaseConfiguration={
'type': 'VECTOR',
'vectorKnowledgeBaseConfiguration': {
'embeddingModelArn': 'arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-embed-text-v2:0'
}
},
storageConfiguration={
'type': 'OPENSEARCH_SERVERLESS',
'opensearchServerlessConfiguration': {
'collectionArn': 'arn:aws:aoss:us-east-1:123456789:collection/abc123',
'vectorIndexName': 'bedrock-kb-index',
'fieldMapping': {
'vectorField': 'embedding',
'textField': 'text',
'metadataField': 'metadata'
}
}
}
)
Bedrock Agents
Agents enable foundation models to take actions by connecting to external tools and APIs.
Example: Customer Service Agent
An agent can:
- Look up customer orders in your database
- Check inventory status via API
- Create support tickets
- Send confirmation emails
Agent Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User Input β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Bedrock Agent β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Foundation Model (Claude) β β
β β Reasons about what actions to take β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Action Group β β Action Group β β Knowledge β β
β β (Lambda) β β (API Schema) β β Base β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Final Response β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Guardrails: Control Model Outputs
Guardrails let you define policies to filter harmful content and protect sensitive data.
Guardrail Capabilities
| Feature | Description |
|---|---|
| Content filters | Block hate, violence, sexual content, etc. |
| Denied topics | Prevent discussion of specific topics |
| Word filters | Block specific words or phrases |
| PII detection | Mask or block personal information |
| Contextual grounding | Reduce hallucinations with source verification |
Creating a Guardrail
import boto3
bedrock = boto3.client('bedrock', region_name='us-east-1')
response = bedrock.create_guardrail(
name='customer-support-guardrail',
description='Guardrail for customer support chatbot',
contentPolicyConfig={
'filtersConfig': [
{'type': 'HATE', 'inputStrength': 'HIGH', 'outputStrength': 'HIGH'},
{'type': 'VIOLENCE', 'inputStrength': 'HIGH', 'outputStrength': 'HIGH'},
]
},
sensitiveInformationPolicyConfig={
'piiEntitiesConfig': [
{'type': 'CREDIT_DEBIT_CARD_NUMBER', 'action': 'BLOCK'},
{'type': 'US_SOCIAL_SECURITY_NUMBER', 'action': 'BLOCK'},
]
},
blockedInputMessaging='I cannot process this request.',
blockedOutputsMessaging='I cannot provide this information.'
)
Model Fine-Tuning
Bedrock supports fine-tuning select models with your own data to improve performance on specific tasks.
Supported Models for Fine-Tuning
Fine-tuning support varies by model and Region. Check the current Bedrock model catalog before choosing a base model.
Fine-Tuning Process
- Prepare training data - JSONL format with prompt/completion pairs
- Upload to S3 - Training data in your bucket
- Create fine-tuning job - Specify base model and hyperparameters
- Deploy custom model - Check the available hosting option for your model
Training Data Format
{"prompt": "Summarize this support ticket:", "completion": "Customer reports login issue..."}
{"prompt": "Summarize this support ticket:", "completion": "User cannot reset password..."}
Best Practices
1. Start with Smaller Models
Use a lower-cost model available in your Region for development and testing. Move to a larger model only when needed for production quality.
2. Implement Caching
Cache common responses to reduce costs:
import hashlib
def get_cached_or_call(prompt, cache):
cache_key = hashlib.md5(prompt.encode()).hexdigest()
if cache_key in cache:
return cache[cache_key]
response = bedrock.converse(...)
cache[cache_key] = response
return response
3. Use Streaming for Long Responses
import os
response = bedrock.converse_stream(
modelId=os.environ["BEDROCK_MODEL_ID"],
messages=[{"role": "user", "content": [{"text": "Write a long story"}]}]
)
for event in response['stream']:
if 'contentBlockDelta' in event:
print(event['contentBlockDelta']['delta']['text'], end='')
4. Monitor Costs
Set up CloudWatch alarms for Bedrock metrics:
InvocationCount- Track usage volumeInvocationLatency- Monitor response timesTokenCount- Watch token consumption
5. Use VPC Endpoints for Security
aws ec2 create-vpc-endpoint \
--vpc-id vpc-123456 \
--service-name com.amazonaws.us-east-1.bedrock-runtime \
--vpc-endpoint-type Interface
Bedrock vs OpenAI vs Direct Anthropic
| Factor | AWS Bedrock | OpenAI API | Anthropic Direct |
|---|---|---|---|
| Model variety | Multiple providers | OpenAI only | Claude only |
| AWS integration | Native | Manual | Manual |
| Enterprise compliance | Depends on service and configuration | Depends on service and configuration | Depends on service and configuration |
| Pricing | Check current model and Region | Check current rates | Check current rates |
| Fine-tuning | Model dependent | Model dependent | Model dependent |
| Setup complexity | AWS knowledge needed | Simple API key | Simple API key |
| Which should I use / when | You need AWS integration and its controls | Your application uses OpenAI models | Your application uses Anthropic models directly |
Getting Started Checklist
- Enable Bedrock in your AWS account
- Request model access for the models you need
- Set up IAM permissions for your users/services
- Start with Converse API for model-agnostic code
- Test with Haiku/Titan before using expensive models
- Add Guardrails for production deployments
- Monitor costs with CloudWatch and billing alerts
AWS Bedrock lowers the barrier to building production AI applications while providing enterprise-grade security and compliance. Start experimenting with the playground in the AWS console, then move to the API for production workloads.