28 min
Lesson 3 of 4
Production Operations and Optimization
From the course AWS Bedrock Advanced
Run production AI workloads on Bedrock with proper monitoring, cost management, and optimization.
Cost Management
Pricing Model
- On-Demand: Pay per token, no commitments
- Provisioned Throughput: Reserved capacity for consistent workloads
- Batch Inference: 50% discount for async, non-urgent workloads
Provisioned Throughput
# Purchase provisioned throughput for high-volume
commitment = bedrock.create_provisioned_model_throughput(
modelUnits=2, # Model units determine capacity
provisionedModelName="prod-claude-throughput",
modelId="anthropic.claude-3-5-sonnet-20241022-v2:0",
commitmentDuration="SixMonths" # 40% discount vs monthly
)
Batch Inference
# Submit batch job for 50% cost savings
bedrock.create_model_invocation_job(
jobName="batch-classification-job",
modelId="anthropic.claude-3-haiku-20240307-v1:0",
clientRequestToken="unique-token",
roleArn="arn:aws:iam::account:role/bedrock-batch-role",
inputDataConfig={
"s3InputDataConfig": {
"s3Uri": "s3://my-bucket/inputs/",
"s3InputFormat": "JSONL"
}
},
outputDataConfig={
"s3OutputDataConfig": {"s3Uri": "s3://my-bucket/outputs/"}
}
)
Monitoring
CloudWatch Metrics
cloudwatch = boto3.client('cloudwatch')
# Bedrock automatically publishes metrics
# Key metrics to monitor:
# - InvocationLatency
# - InputTokenCount
# - OutputTokenCount
# - InvocationClientErrors
# - InvocationServerErrors
# Create alarm for high error rates
cloudwatch.put_metric_alarm(
AlarmName='BedrockHighErrorRate',
MetricName='InvocationClientErrors',
Namespace='AWS/Bedrock',
Statistic='Sum',
Period=300,
EvaluationPeriods=3,
Threshold=10,
ComparisonOperator='GreaterThanThreshold'
)
Guardrails
# Create content safety guardrails
guardrail = bedrock.create_guardrail(
name="SafeGuardrail",
contentPolicyConfig={
"filtersConfig": [
{"type": "HATE", "inputStrength": "HIGH", "outputStrength": "HIGH"},
{"type": "VIOLENCE", "inputStrength": "MEDIUM", "outputStrength": "HIGH"}
]
},
topicPolicyConfig={
"topicsConfig": [{
"name": "Financial_Advice",
"definition": "Specific investment recommendations or financial advice",
"type": "DENY"
}]
}
)
Key Takeaways
- •Provisioned throughput with six-month commitment delivers 40% cost savings
- •Batch inference provides 50% discount for asynchronous non-urgent workloads
- •CloudWatch metrics track latency, token counts, and error rates automatically
- •Guardrails implement content safety controls at the API gateway level
0 of 4 lessons marked complete
Progress is kept in this browser only.