Provides AWS CloudFormation patterns for Amazon Bedrock resources including agents, knowledge bases, data sources, guardrails, prompts, flows, and inference profiles. Use when creating Bedrock agents with action groups, implementing RAG with knowledge bases, configuring vector stores, setting up content moderation guardrails, managing prompts, orchestrating workflows with flows, and configuring inference profiles for model optimization.
Provides AWS CloudFormation patterns for Amazon Bedrock resources including agents, knowledge bases, data sources, guardrails, prompts, flows, and inference profiles. Use when creating Bedrock agents with action groups, implementing RAG with knowledge bases, configuring vector stores, setting up content moderation guardrails, managing prompts, orchestrating workflows with flows, and configuring inference profiles for model optimization.
allowed-tools
Read, Write, Bash
AWS CloudFormation Amazon Bedrock
Overview
Creates production-ready AI infrastructure using AWS CloudFormation templates for Amazon Bedrock. Covers Bedrock agents, knowledge bases for RAG implementations, data source connectors, guardrails for content moderation, prompt management, workflow orchestration with flows, and inference profiles for optimized model access.
When to Use
Creating Bedrock agents with action groups
Implementing RAG with knowledge bases
Configuring S3 or web crawl data sources
Setting up content moderation guardrails
Managing prompt templates
Orchestrating AI workflows with Bedrock Flows
Configuring inference profiles for multi-model access
Organizing templates with Parameters and cross-stack references
BedrockAgent:Type:AWS::Bedrock::AgentProperties:AgentName:!Sub"${AWS::StackName}-agent"AgentResourceRoleArn:!GetAttAgentRole.ArnFoundationModelArn:!Sub"arn:aws:bedrock:${AWS::Region}::foundation-model/${FoundationModel}"AutoPrepare:trueInstruction:|
You are a helpful assistant. Use the knowledge base to answer questions.
Guardrail:Type:AWS::Bedrock::GuardrailProperties:Name:!Sub"${AWS::StackName}-guardrail"BlockedInputMessaging:"I cannot help with that request."ContentPolicyConfig:filtersConfig:-type:PROFANITY-type:MISCONDUCT
# Check agent status
aws bedrock-agent get-agent --agent-id $(aws cloudformation describe-stacks --stack-name STACK_NAME --query 'Stacks[0].Outputs[?OutputKey==`AgentId`].OutputValue' --output text)
# Check knowledge base sync status
aws bedrock-agent list-knowledge-bases --agent-id AGENT_ID
# Test guardrail
aws bedrock-runtime apply_guardrail --guardrail-identifier GUARDRAIL_ID --source SOURCE
Examples
Minimal RAG Agent Template
Complete working template for a RAG-enabled agent:
AWSTemplateFormatVersion:"2010-09-09"Description:"Bedrock RAG Agent with Knowledge Base"Parameters:FoundationModel:Type:StringDefault:anthropic.claude-3-sonnet-20240229-v1:0Resources:# IAM Role for AgentAgentRole:Type:AWS::IAM::RoleProperties:RoleName:!Sub"${AWS::StackName}-agent-role"AssumeRolePolicyDocument:Version:"2012-10-17"Statement:-Effect:AllowPrincipal:Service:bedrock.amazonaws.comAction:sts:AssumeRolePolicies:-PolicyName:InvokeModelPolicyDocument:Version:"2012-10-17"Statement:-Effect:AllowAction:bedrock:InvokeModelResource:"*"# IAM Role for Knowledge BaseKnowledgeBaseRole:Type:AWS::IAM::RoleProperties:RoleName:!Sub"${AWS::StackName}-kb-role"AssumeRolePolicyDocument:Version:"2012-10-17"Statement:-Effect:AllowPrincipal:Service:bedrock.amazonaws.comAction:sts:AssumeRolePolicies:-PolicyName:S3AccessPolicyDocument:Version:"2012-10-17"Statement:-Effect:AllowAction:s3:GetObjectResource:!Sub"${DataBucket.Arn}/*"# S3 Bucket for DocumentsDataBucket:Type:AWS::S3::Bucket# Knowledge BaseKnowledgeBase:Type:AWS::Bedrock::KnowledgeBaseProperties:Name:!Sub"${AWS::StackName}-kb"RoleArn:!GetAttKnowledgeBaseRole.ArnKnowledgeBaseConfiguration:Type:VECTORVectorKnowledgeBaseConfiguration:EmbeddingModelArn:!Sub"arn:aws:bedrock:${AWS::Region}::embedding-model/amazon.titan-embed-text-v1"# Data SourceDataSource:Type:AWS::Bedrock::DataSourceProperties:KnowledgeBaseId:!RefKnowledgeBaseName:!Sub"${AWS::StackName}-ds"Type:S3DataSourceConfiguration:S3Configuration:BucketArn:!GetAttDataBucket.Arn# Bedrock AgentBedrockAgent:Type:AWS::Bedrock::AgentProperties:AgentName:!Sub"${AWS::StackName}-agent"AgentResourceRoleArn:!GetAttAgentRole.ArnFoundationModelArn:!Sub"arn:aws:bedrock:${AWS::Region}::foundation-model/${FoundationModel}"AutoPrepare:trueInstruction:|
You are a helpful assistant. Use the knowledge base to answer user questions accurately.
Outputs:AgentId:Description:BedrockAgentIDValue:!GetAttBedrockAgent.AgentIdKnowledgeBaseId:Description:KnowledgeBaseIDValue:!RefKnowledgeBase
Guardrail with Content Filtering
Resources:Guardrail:Type:AWS::Bedrock::GuardrailProperties:Name:!Sub"${AWS::StackName}-guardrail"blockedInputMessaging:"Content blocked by safety filters."blockedOutputMessaging:"Response filtered for safety."contentPolicyConfig:filtersConfig:-type:PROFANITYinputStrength:HIGHoutputStrength:HIGH-type:MISCONDUCTinputStrength:HIGHoutputStrength:HIGHsensitiveInformationPolicyConfig:piiEntitiesConfig:-type:EMAILaction:ANONYMIZE-type:SSNaction:BLOCK
Best Practices
Security
Use least privilege IAM policies for agent and knowledge base roles
Restrict web crawl data sources to trusted internal domains
Encrypt sensitive data in knowledge bases
Parameterize all TemplateURL values for nested stacks
Cost Optimization
Select appropriate model size for task complexity
Configure retrieval filtering to reduce token usage
Set chunk size limits to control storage costs
Monitor usage with CloudWatch dashboards
Performance
Optimize chunk size for embedding quality
Use provisioned throughput for high-traffic vector stores
Configure appropriate knowledge base sync intervals
Implement caching for frequently accessed content
Validation
Always run aws cloudformation validate-template before deploy
Verify agent status after stack creation completes