
Aws Cloudformation Bedrock
- 71 installs
- 318 repo stars
- Updated June 22, 2026
- giuseppe-trisciuoglio/developer-kit
Author AWS CloudFormation templates for Amazon Bedrock agents, knowledge bases, guardrails, prompts, flows, and inference profiles.
About
Provides CloudFormation patterns to provision Amazon Bedrock AI infrastructure including agents with action groups, RAG knowledge bases, vector stores, and content-moderation guardrails. A developer uses it to stand up Bedrock-based AI systems as code.
- Covers RAG knowledge bases and vector store configs (OpenSearch, Pinecone, pgvector)
- Includes guardrails, prompt management, flows, and inference profiles
Aws Cloudformation Bedrock by the numbers
- 71 all-time installs (skills.sh)
- Ranked #648 of 1,039 Cloud & Infrastructure skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill aws-cloudformation-bedrockAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 71 |
|---|---|
| repo stars | ★ 318 |
| Last updated | June 22, 2026 |
| Repository | giuseppe-trisciuoglio/developer-kit ↗ |
What it does
Author AWS CloudFormation templates for Amazon Bedrock agents, knowledge bases, guardrails, prompts, flows, and inference profiles.
Files
AWS CloudFormation Amazon Bedrock
Overview
Create production-ready AI infrastructure using AWS CloudFormation templates for Amazon Bedrock. This skill 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
Use this skill when:
- Creating Bedrock agents with action groups and function definitions
- Implementing Retrieval-Augmented Generation (RAG) with knowledge bases
- Configuring data sources (S3, web crawl, custom connectors)
- Setting up vector store configurations (OpenSearch, Pinecone, pgvector)
- Creating content moderation guardrails
- Managing prompt templates and versions
- Orchestrating AI workflows with Bedrock Flows
- Configuring inference profiles for multi-model access
- Setting up application inference profiles for optimized model routing
- Organizing templates with Parameters, Outputs, Mappings, Conditions
- Implementing cross-stack references with export/import
CloudFormation Template Structure
Base Template with Standard Format
AWSTemplateFormatVersion: 2010-09-09
Description: Amazon Bedrock agent with knowledge base for RAG
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Agent Configuration
Parameters:
- AgentName
- AgentDescription
- FoundationModel
- Label:
default: Knowledge Base Settings
Parameters:
- KnowledgeBaseName
- VectorStoreType
- EmbeddingModel
- Label:
default: Deployment Settings
Parameters:
- Environment
- DeployStage
Parameters:
AgentName:
Type: String
Default: my-bedrock-agent
Description: Name of the Bedrock agent
AgentDescription:
Type: String
Default: Agent for customer support automation
Description: Description of the agent's purpose
FoundationModel:
Type: String
Default: anthropic.claude-v2:1
Description: Foundation model for the agent
AllowedValues:
- anthropic.claude-v2:1
- anthropic.claude-v3:5
- anthropic.claude-sonnet-4-20250514
- amazon.titan-text-express-v1
- meta.llama3-70b-instruct-v1:0
KnowledgeBaseName:
Type: String
Default: my-knowledge-base
Description: Name of the knowledge base
VectorStoreType:
Type: String
Default: OPENSEARCH_SERVERLESS
Description: Vector store type for knowledge base
AllowedValues:
- OPENSEARCH_SERVERLESS
- PINECONE
- PGVECTOR
- REDIS
EmbeddingModel:
Type: String
Default: amazon.titan-embed-text-v1
Description: Embedding model for vectorization
AllowedValues:
- amazon.titan-embed-text-v1
- amazon.titan-embed-text-v2:0
- cohere.embed-multilingual-v3:0
Environment:
Type: String
Default: dev
AllowedValues:
- dev
- staging
- production
Mappings:
EnvironmentConfig:
dev:
AgentVersion: DRAFT
IndexCapacity: 1
InferenceUnit: 1
staging:
AgentVersion: DRAFT
IndexCapacity: 5
InferenceUnit: 2
production:
AgentVersion: RELEASE
IndexCapacity: 10
InferenceUnit: 5
Conditions:
IsProduction: !Equals [!Ref Environment, production]
UseOpenSearch: !Equals [!Ref VectorStoreType, OPENSEARCH_SERVERLESS]
Transform:
- AWS::Serverless-2016-10-31
Resources:
# Bedrock Agent
BedrockAgent:
Type: AWS::Bedrock::Agent
Properties:
AgentName: !Ref AgentName
Description: !Ref AgentDescription
FoundationModel: !Ref FoundationModel
IdleSessionTTLInSeconds: 1800
AgentResourceRoleArn: !GetAtt AgentResourceRole.Arn
AutoPrepare: true
# Agent Resource Role
AgentResourceRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-bedrock-agent-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-bedrock-agent-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/${FoundationModel}"
Outputs:
AgentId:
Description: ID of the Bedrock agent
Value: !GetAtt BedrockAgent.AgentId
Export:
Name: !Sub "${AWS::StackName}-AgentId"
AgentAliasId:
Description: Alias ID of the Bedrock agent
Value: !GetAtt BedrockAgent.LatestAgentAliasId
Export:
Name: !Sub "${AWS::StackName}-AgentAliasId"
AgentArn:
Description: ARN of the Bedrock agent
Value: !GetAtt BedrockAgent.AgentArn
Export:
Name: !Sub "${AWS::StackName}-AgentArn"Best Practices for Parameters
AWS-Specific Parameter Types
Parameters:
# AWS-specific types for validation
AgentId:
Type: AWS::Bedrock::Agent::Id
Description: Existing Bedrock agent ID
KnowledgeBaseId:
Type: AWS::Bedrock::KnowledgeBase::Id
Description: Existing knowledge base ID
GuardrailId:
Type: AWS::Bedrock::Guardrail::Id
Description: Existing guardrail ID
FoundationModelArn:
Type: AWS::Bedrock::FoundationModel::Arn
Description: ARN of foundation model
FoundationModelIdentifier:
Type: AWS::Bedrock::FoundationModel::Identifier
Description: Identifier of foundation model
S3BucketArn:
Type: AWS::S3::Bucket::Arn
Description: S3 bucket ARN for data sources
IAMRoleArn:
Type: AWS::IAM::Role::Arn
Description: IAM role for Bedrock operations
KMSKeyArn:
Type: AWS::KMS::Key::Arn
Description: KMS key for encryptionParameter Constraints
Parameters:
AgentName:
Type: String
Default: my-agent
Description: Bedrock agent name
ConstraintDescription: Must be 1-100 characters, alphanumeric and underscores
MinLength: 1
MaxLength: 100
AllowedPattern: "[a-zA-Z0-9_]+"
KnowledgeBaseName:
Type: String
Default: my-kb
Description: Knowledge base name
ConstraintDescription: Must be 1-100 characters
MinLength: 1
MaxLength: 100
MaxTokens:
Type: Number
Default: 4096
Description: Maximum tokens for model response
MinValue: 1
MaxValue: 100000
ConstraintDescription: Must be between 1 and 100000
Temperature:
Type: Number
Default: 0.7
Description: Temperature for model generation
MinValue: 0
MaxValue: 1
ConstraintDescription: Must be between 0 and 1SSM Parameter References for Model Identifiers
Parameters:
ClaudeModelIdentifier:
Type: AWS::SSM::Parameter::Value<String>
Default: /bedrock/models/claude-identifier
Description: Claude model identifier from SSM
EmbeddingModelIdentifier:
Type: AWS::SSM::Parameter::Value<String>
Default: /bedrock/models/embedding-identifier
Description: Embedding model identifier from SSMOutputs and Cross-Stack References
Export/Import Patterns
# Stack A - Bedrock Infrastructure Stack
AWSTemplateFormatVersion: 2010-09-09
Description: Bedrock infrastructure stack with agents and knowledge bases
Resources:
# Bedrock Agent
CustomerSupportAgent:
Type: AWS::Bedrock::Agent
Properties:
AgentName: !Sub "${AWS::StackName}-support-agent"
Description: Agent for customer support
FoundationModel: anthropic.claude-v3:5
AgentResourceRoleArn: !GetAtt AgentRole.Arn
AutoPrepare: true
# Knowledge Base
SupportKnowledgeBase:
Type: AWS::Bedrock::KnowledgeBase
Properties:
KnowledgeBaseName: !Sub "${AWS::StackName}-support-kb"
Description: Knowledge base for customer support
EmbeddingModelArn: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/amazon.titan-embed-text-v1"
VectorKnowledgeBaseConfiguration:
VectorStoreConfiguration:
OpensearchServerlessConfiguration:
CollectionArn: !Ref OpenSearchCollectionArn
VectorIndexName: knowledge-base-index
FieldMapping:
VectorField: vector
TextField: text
MetadataField: metadata
RoleArn: !GetAtt KnowledgeBaseRole.Arn
Outputs:
AgentId:
Description: ID of the Bedrock agent
Value: !GetAtt CustomerSupportAgent.AgentId
Export:
Name: !Sub "${AWS::StackName}-AgentId"
AgentAliasId:
Description: Alias ID of the Bedrock agent
Value: !GetAtt CustomerSupportAgent.LatestAgentAliasId
Export:
Name: !Sub "${AWS::StackName}-AgentAliasId"
AgentArn:
Description: ARN of the Bedrock agent
Value: !GetAtt CustomerSupportAgent.AgentArn
Export:
Name: !Sub "${AWS::StackName}-AgentArn"
KnowledgeBaseId:
Description: ID of the knowledge base
Value: !GetAtt SupportKnowledgeBase.KnowledgeBaseId
Export:
Name: !Sub "${AWS::StackName}-KnowledgeBaseId"
KnowledgeBaseArn:
Description: ARN of the knowledge base
Value: !GetAtt SupportKnowledgeBase.KnowledgeBaseArn
Export:
Name: !Sub "${AWS::StackName}-KnowledgeBaseArn"# Stack B - Application Stack (imports from Stack A)
AWSTemplateFormatVersion: 2010-09-09
Description: Application stack using Bedrock agent
Parameters:
BedrockStackName:
Type: String
Default: bedrock-infrastructure
Description: Name of the Bedrock infrastructure stack
Resources:
# Lambda function that invokes Bedrock agent
AgentInvokerFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-agent-invoker"
Runtime: python3.11
Handler: handler.invoke_agent
Code:
S3Bucket: !Ref CodeBucket
S3Key: lambda/agent-invoker.zip
Environment:
Variables:
AGENT_ID: !ImportValue
!Sub "${BedrockStackName}-AgentId"
AGENT_ALIAS_ID: !ImportValue
!Sub "${BedrockStackName}-AgentAliasId"
Role: !GetAtt LambdaExecutionRole.Arn
# Lambda Execution Role with Bedrock permissions
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-lambda-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: BedrockAgentInvoke
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- bedrock:InvokeAgent
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:agent/*"Nested Stacks for Modularity
AWSTemplateFormatVersion: 2010-09-09
Description: Main stack with nested Bedrock stacks
Resources:
# Nested stack for agents
AgentsStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: https://s3.amazonaws.com/bucket/bedrock-agents.yaml
TimeoutInMinutes: 15
Parameters:
Environment: !Ref Environment
AgentName: !Ref AgentName
FoundationModel: !Ref FoundationModel
# Nested stack for knowledge bases
KnowledgeBaseStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: https://s3.amazonaws.com/bucket/bedrock-knowledge-base.yaml
TimeoutInMinutes: 15
Parameters:
Environment: !Ref Environment
KnowledgeBaseName: !Ref KnowledgeBaseName
VectorStoreType: !Ref VectorStoreType
# Nested stack for guardrails
GuardrailsStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: https://s3.amazonaws.com/bucket/bedrock-guardrails.yaml
TimeoutInMinutes: 15
Parameters:
Environment: !Ref Environment
GuardrailName: !Ref GuardrailNameBedrock Agents with Action Groups
Agent with Lambda Action Group
AWSTemplateFormatVersion: 2010-09-09
Description: Bedrock agent with Lambda action group for API operations
Parameters:
Environment:
Type: String
Default: dev
AllowedValues:
- dev
- staging
- production
Resources:
# Agent Resource Role
AgentResourceRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-agent-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: BedrockAgentPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
Resource: "*"
- Effect: Allow
Action:
- lambda:InvokeFunction
- lambda:InvokeAsync
Resource: !GetAtt ActionGroupFunction.Arn
# Lambda function for action group
ActionGroupFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-action-group"
Runtime: python3.11
Handler: handler.handler
Code:
S3Bucket: !Ref CodeBucket
S3Key: lambda/action-group.zip
Role: !GetAtt LambdaExecutionRole.Arn
# Lambda Execution Role
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-lambda-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
# Bedrock Agent
ApiAgent:
Type: AWS::Bedrock::Agent
Properties:
AgentName: !Sub "${AWS::StackName}-api-agent"
Description: Agent for API operations
FoundationModel: anthropic.claude-v3:5
AgentResourceRoleArn: !GetAtt AgentResourceRole.Arn
AutoPrepare: true
# Action Group with Lambda function
ApiActionGroup:
Type: AWS::Bedrock::AgentActionGroup
Properties:
AgentId: !Ref ApiAgent
AgentVersion: DRAFT
ActionGroupName: ApiActionGroup
Description: Action group for API operations
ActionGroupExecutor:
Lambda: !Ref ActionGroupFunction
ApiSchema:
S3:
S3BucketName: !Ref ApiSchemaBucket
S3ObjectKey: api-schema.json
SkipModelsInExecution: false
# API Schema in S3
ApiSchemaBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "${AWS::StackName}-api-schema-${AWS::AccountId}-${AWS::Region}"Agent with Knowledge Base Integration
AWSTemplateFormatVersion: 2010-09-09
Description: Bedrock agent with knowledge base for RAG
Parameters:
Environment:
Type: String
Default: dev
Resources:
# Agent Resource Role
AgentResourceRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-agent-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: AgentPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
Resource: "*"
- Effect: Allow
Action:
- bedrock:Retrieve
- bedrock:RetrieveAndGenerate
Resource: !GetAtt KnowledgeBase.KnowledgeBaseArn
# OpenSearch Serverless Collection
OpenSearchCollection:
Type: AWS::OpenSearchServerless::Collection
Properties:
Name: !Sub "${AWS::StackName}-kb-collection"
Type: SEARCH
# OpenSearch Serverless Access Policy
AccessPolicy:
Type: AWS::OpenSearchServerless::AccessPolicy
Properties:
Name: !Sub "${AWS::StackName}-access-policy"
Policy: !Sub |
[
{
"Rules": [
{
"Resource": ["collection/${OpenSearchCollection.id}"],
"Permission": ["aoss:*"]
},
{
"Resource": ["index/collection/${OpenSearchCollection.id}/*"],
"Permission": ["aoss:*"]
}
],
"Principal": ["${AgentResourceRole.Arn}"]
}
]
Type: data
# Knowledge Base
KnowledgeBase:
Type: AWS::Bedrock::KnowledgeBase
Properties:
KnowledgeBaseName: !Sub "${AWS::StackName}-kb"
Description: Knowledge base for document retrieval
EmbeddingModelArn: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/amazon.titan-embed-text-v1"
VectorKnowledgeBaseConfiguration:
VectorStoreConfiguration:
OpensearchServerlessConfiguration:
CollectionArn: !GetAtt OpenSearchCollection.Arn
VectorIndexName: kb-index
FieldMapping:
VectorField: vector
TextField: text
MetadataField: metadata
RoleArn: !GetAtt AgentResourceRole.Arn
# Bedrock Agent with knowledge base
RAGAgent:
Type: AWS::Bedrock::Agent
Properties:
AgentName: !Sub "${AWS::StackName}-rag-agent"
Description: Agent with knowledge base for RAG
FoundationModel: anthropic.claude-v3:5
AgentResourceRoleArn: !GetAtt AgentResourceRole.Arn
AutoPrepare: true
KnowledgeBases:
- KnowledgeBaseId: !Ref KnowledgeBase
Description: Main knowledge base for document retrieval
# Data Source for Knowledge Base
KnowledgeBaseDataSource:
Type: AWS::Bedrock::DataSource
Properties:
KnowledgeBaseId: !Ref KnowledgeBase
DataSourceName: !Sub "${AWS::StackName}-datasource"
Description: S3 data source for documents
DataSourceConfiguration:
S3Configuration:
BucketArn: !Ref DocumentBucket
InclusionPrefixes:
- documents/
- pdfs/
VectorIngestionConfiguration:
ChunkingConfiguration:
ChunkingStrategy: FIXED_SIZE
FixedSizeChunking:
MaxTokens: 512
OverlapPercentage: 20
# Document Bucket
DocumentBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "${AWS::StackName}-documents-${AWS::AccountId}-${AWS::Region}"Knowledge Bases and Vector Stores
Knowledge Base with OpenSearch Serverless
AWSTemplateFormatVersion: 2010-09-09
Description: Knowledge base with OpenSearch Serverless vector store
Resources:
# OpenSearch Serverless Collection
VectorCollection:
Type: AWS::OpenSearchServerless::Collection
Properties:
Name: !Sub "${AWS::StackName}-vector-collection"
Type: SEARCH
# Security Policy
SecurityPolicy:
Type: AWS::OpenSearchServerless::SecurityPolicy
Properties:
Name: !Sub "${AWS::StackName}-security-policy"
Policy: !Sub |
{
"Rules": [
{
"Resource": ["collection/${VectorCollection.id}"],
"ResourceType": "collection"
}
],
"Principal": ["*"]
}
Type: encryption
# Access Policy
AccessPolicy:
Type: AWS::OpenSearchServerless::AccessPolicy
Properties:
Name: !Sub "${AWS::StackName}-access-policy"
Policy: !Sub |
[
{
"Rules": [
{
"Resource": ["collection/${VectorCollection.id}"],
"Permission": ["aoss:*"]
}
],
"Principal": ["${KnowledgeBaseRole.Arn}"]
}
]
Type: data
# Knowledge Base Role
KnowledgeBaseRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-kb-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: KnowledgeBasePolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- aoss:APIAccessAll
Resource: !GetAtt VectorCollection.Arn
- Effect: Allow
Action:
- s3:GetObject
Resource: !Sub "${DocumentBucket.Arn}/*"
# Knowledge Base
KnowledgeBase:
Type: AWS::Bedrock::KnowledgeBase
Properties:
KnowledgeBaseName: !Sub "${AWS::StackName}-knowledge-base"
Description: Vector knowledge base with OpenSearch
EmbeddingModelArn: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/amazon.titan-embed-text-v1"
VectorKnowledgeBaseConfiguration:
VectorStoreConfiguration:
OpensearchServerlessConfiguration:
CollectionArn: !GetAtt VectorCollection.Arn
VectorIndexName: knowledge-index
FieldMapping:
VectorField: vector
TextField: text
MetadataField: metadata
RoleArn: !GetAtt KnowledgeBaseRole.Arn
# Data Source
DataSource:
Type: AWS::Bedrock::DataSource
Properties:
KnowledgeBaseId: !Ref KnowledgeBase
DataSourceName: !Sub "${AWS::StackName}-s3-datasource"
DataSourceConfiguration:
S3Configuration:
BucketArn: !Ref DocumentBucket
VectorIngestionConfiguration:
ChunkingConfiguration:
ChunkingStrategy: FIXED_SIZE
FixedSizeChunking:
MaxTokens: 1000
OverlapPercentage: 10Knowledge Base with Pinecone
AWSTemplateFormatVersion: 2010-09-09
Description: Knowledge base with Pinecone vector store
Parameters:
PineconeApiKey:
Type: String
Description: Pinecone API key (use Secrets Manager in production)
NoEcho: true
Resources:
# Knowledge Base Role
KnowledgeBaseRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-kb-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: SecretsManagerAccess
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
Resource: !Ref PineconeSecretArn
# Pinecone Connection Configuration
PineconeConnection:
Type: AWS::SecretsManager::Secret
Properties:
Name: !Sub "${AWS::StackName}-pinecone-credentials"
SecretString: !Sub '{"PINECONE_API_KEY":"${PineconeApiKey}"}'
# Knowledge Base with Pinecone
KnowledgeBase:
Type: AWS::Bedrock::KnowledgeBase
Properties:
KnowledgeBaseName: !Sub "${AWS::StackName}-pinecone-kb"
Description: Knowledge base with Pinecone vector store
EmbeddingModelArn: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/amazon.titan-embed-text-v1"
VectorKnowledgeBaseConfiguration:
VectorStoreConfiguration:
PineconeConfiguration:
ConnectionString: !Ref PineconeConnectionString
CredentialsSecretArn: !Ref PineconeConnection
Namespace: !Ref PineconeNamespace
FieldMapping:
TextField: text
MetadataField: metadata
RoleArn: !GetAtt KnowledgeBaseRole.Arn
# Data Source
DataSource:
Type: AWS::Bedrock::DataSource
Properties:
KnowledgeBaseId: !Ref KnowledgeBase
DataSourceName: !Sub "${AWS::StackName}-pinecone-ds"
DataSourceConfiguration:
S3Configuration:
BucketArn: !Ref DocumentBucketGuardrails for Content Moderation
Guardrail with Multiple Filters
AWSTemplateFormatVersion: 2010-09-09
Description: Bedrock guardrail for content moderation
Parameters:
Environment:
Type: String
Default: dev
AllowedValues:
- dev
- staging
- production
Resources:
# Guardrail
ContentGuardrail:
Type: AWS::Bedrock::Guardrail
Properties:
GuardrailName: !Sub "${AWS::StackName}-guardrail"
Description: Content moderation guardrail
# Topic Policy - Define denied topics
TopicPolicy:
Topics:
- Name: FinancialAdvice
Definition: Providing personalized financial investment advice
Examples:
- "What stocks should I buy?"
- "Should I invest in crypto?"
Type: DENIED
- Name: MedicalAdvice
Definition: Providing medical diagnosis or treatment recommendations
Examples:
- "What medication should I take?"
- "Do I have COVID?"
Type: DENIED
# Sensitive Information Policy
SensitiveInformationPolicy:
PiiEntities:
- Name: EMAIL
Action: MASK
- Name: PHONE_NUMBER
Action: MASK
- Name: SSN
Action: BLOCK
- Name: CREDIT_DEBIT_NUMBER
Action: BLOCK
Regexes:
- Name: CustomPattern
Pattern: "\\d{3}-\\d{2}-\\d{4}"
Action: MASK
# Word Policy - Custom blocked words
WordPolicy:
Words:
- Text: "spam"
- Text: "scam"
- Text: "fraud"
ManagedWordLists:
- Type: PROFANITY
# Content Policy
ContentPolicy:
Filters:
- Type: PROFANITY
InputStrength: LOW
OutputStrength: LOW
- Type: HATE
InputStrength: MEDIUM
OutputStrength: HIGH
- Type: SEXUAL
InputStrength: LOW
OutputStrength: MEDIUM
- Type: VIOLENCE
InputStrength: MEDIUM
OutputStrength: HIGH
# Contextual Grounding Policy
ContextualGroundingPolicy:
Filters:
- Type: GROUNDING
Threshold: 0.7
- Type: RELEVANCE
Threshold: 0.7
Outputs:
GuardrailId:
Description: ID of the guardrail
Value: !GetAtt ContentGuardrail.GuardrailId
Export:
Name: !Sub "${AWS::StackName}-GuardrailId"
GuardrailVersion:
Description: Version of the guardrail
Value: !GetAtt ContentGuardrail.GuardrailVersion
Export:
Name: !Sub "${AWS::StackName}-GuardrailVersion"
GuardrailArn:
Description: ARN of the guardrail
Value: !GetAtt ContentGuardrail.GuardrailArn
Export:
Name: !Sub "${AWS::StackName}-GuardrailArn"Bedrock Flows for Workflow Orchestration
Flow with Multiple Nodes
AWSTemplateFormatVersion: 2010-09-09
Description: Bedrock Flow for AI workflow orchestration
Resources:
# Flow Role
FlowRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-flow-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: FlowPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
Resource: "*"
- Effect: Allow
Action:
- bedrock:Retrieve
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:knowledge-base/*"
# Bedrock Flow
ProcessingFlow:
Type: AWS::Bedrock::Flow
Properties:
Name: !Sub "${AWS::StackName}-processing-flow"
Description: Flow for processing customer requests
ExecutionRoleArn: !GetAtt FlowRole.Arn
Definition:
StartAt: IntentClassifier
Nodes:
IntentClassifier:
Type: Classifier
Name: IntentClassifier
Description: Classifies the user intent
Configuration:
BedrockClassifierConfiguration:
BedrockFoundationModelConfiguration:
ModelId: anthropic.claude-v3:5
InferenceConfiguration:
Temperature: 0.0
InputConfiguration:
TextInput:
Name: user_input
OutputConfiguration:
StructuredOutput:
Name: intent
Description: Classified intent
JsonOutputSchema:
properties:
intent:
type: string
enum:
- product_inquiry
- order_status
- refund_request
- general_question
confidence:
type: number
Transitions:
Next:
ProductInquiry: product_inquiry
OrderStatus: order_status
RefundRequest: refund_request
GeneralQuestion: "*"
ProductInquiry:
Type: KnowledgeBase
Name: ProductInquiry
Description: Retrieves product information
Configuration:
KnowledgeBaseConfiguration:
KnowledgeBaseId: !Ref ProductKnowledgeBase
ModelId: anthropic.claude-v3:5
Transitions:
Next: ResponseGenerator
OrderStatus:
Type: LambdaFunction
Name: OrderStatus
Description: Checks order status
Configuration:
LambdaConfiguration:
LambdaArn: !GetAtt OrderStatusFunction.Arn
Transitions:
Next: ResponseGenerator
RefundRequest:
Type: LambdaFunction
Name: RefundRequest
Description: Processes refund requests
Configuration:
LambdaConfiguration:
LambdaArn: !GetAtt RefundFunction.Arn
Transitions:
Next: ResponseGenerator
GeneralQuestion:
Type: Model
Name: GeneralQuestion
Description: Answers general questions
Configuration:
BedrockModelConfiguration:
ModelId: anthropic.claude-v3:5
InferenceConfiguration:
Temperature: 0.7
MaxTokens: 1000
Transitions:
Next: ResponseGenerator
ResponseGenerator:
Type: Model
Name: ResponseGenerator
Description: Generates final response
Configuration:
BedrockModelConfiguration:
ModelId: anthropic.claude-v3:5
InferenceConfiguration:
Temperature: 0.7
MaxTokens: 2000
IsEnd: true
Outputs:
FlowId:
Description: ID of the flow
Value: !Ref ProcessingFlow
Export:
Name: !Sub "${AWS::StackName}-FlowId"
FlowArn:
Description: ARN of the flow
Value: !GetAtt ProcessingFlow.Arn
Export:
Name: !Sub "${AWS::StackName}-FlowArn"Inference Profiles for Multi-Model Access
Application Inference Profile
AWSTemplateFormatVersion: 2010-09-09
Description: Application inference profile for optimized model access
Parameters:
InferenceProfileName:
Type: String
Default: production-profile
Description: Name of the inference profile
Resources:
# Application Inference Profile
ProductionProfile:
Type: AWS::Bedrock::ApplicationInferenceProfile
Properties:
ApplicationInferenceProfileName: !Ref InferenceProfileName
Description: Production inference profile for multi-model access
ModelSource:
CopyFrom: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:application-inference-profile/*"
InferenceConfiguration:
Text:
anthropic.claude-v3:5:
Temperature: 0.7
MaxTokens: 4096
TopP: 0.999
anthropic.claude-sonnet-4-20250514:
Temperature: 0.7
MaxTokens: 4096
Outputs:
InferenceProfileId:
Description: ID of the inference profile
Value: !Ref ProductionProfile
Export:
Name: !Sub "${AWS::StackName}-InferenceProfileId"
InferenceProfileArn:
Description: ARN of the inference profile
Value: !GetAtt ProductionProfile.Arn
Export:
Name: !Sub "${AWS::StackName}-InferenceProfileArn"Best Practices
Security
- Use IAM roles with minimum necessary permissions for Bedrock operations
- Enable encryption for all knowledge base data and vectors
- Use guardrails for content moderation in production deployments
- Implement VPC endpoints for private Bedrock access
- Use AWS Secrets Manager for API keys and credentials
- Configure cross-account access carefully with proper IAM policies
- Audit Bedrock API calls with CloudTrail
Performance
- Choose appropriate embedding models based on use case
- Optimize chunking strategies for knowledge base ingestion
- Use inference profiles for consistent latency across models
- Monitor token usage and implement rate limiting
- Configure appropriate timeouts for long-running operations
- Use provisioned throughput for predictable workloads
- Cache frequently accessed knowledge base results
Monitoring
- Enable CloudWatch metrics for Bedrock API calls
- Create alarms for throttled requests and errors
- Monitor knowledge base retrieval latency
- Track token usage and costs per model
- Implement logging for agent interactions
- Monitor guardrail violations and content moderation
- Use Bedrock model invocation logs for debugging
Cost Optimization
- Use on-demand pricing for variable workloads
- Implement caching for frequent model invocations
- Choose appropriate model sizes for task requirements
- Use knowledge base retrieval filtering to reduce costs
- Implement batch processing for non-real-time workloads
- Monitor and optimize token consumption
CloudFormation Stack Management Best Practices
Stack Policies
Resources:
BedrockAgent:
Type: AWS::Bedrock::Agent
Properties:
AgentName: !Sub "${AWS::StackName}-agent"
# Stack policy to protect Bedrock resources
StackPolicy:
Type: AWS::CloudFormation::StackPolicy
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal: "*"
Action: "Update:*"
Resource: "*"
- Effect: Deny
Principal: "*"
Action:
- Update:Delete
Resource:
- LogicalId: BedrockAgent
ResourceType: AWS::Bedrock::AgentDrift Detection
# Detect drift on a stack
aws cloudformation detect-drift --stack-name my-bedrock-stack
# Get resource drift status
aws cloudformation describe-stack-resource-drifts \
--stack-name my-bedrock-stackRelated Resources
- Amazon Bedrock Documentation
- AWS CloudFormation User Guide
- Bedrock Agents
- Bedrock Knowledge Bases
- Bedrock Guardrails
- Bedrock Flows
Additional Files
For complete details on resources and their properties, see:
- REFERENCE.md - Detailed reference guide for all Bedrock CloudFormation resources
- EXAMPLES.md - Complete production-ready examples
AWS CloudFormation Bedrock - Examples
This file contains comprehensive examples for Amazon Bedrock patterns with CloudFormation.
Example 1: Complete Bedrock Agent with Action Groups and Knowledge Base
Complete agent implementation with Lambda action group and knowledge base for RAG.
AWSTemplateFormatVersion: 2010-09-09
Description: Complete Bedrock agent with action group and knowledge base
Parameters:
Environment:
Type: String
Default: dev
AllowedValues:
- dev
- staging
- production
AgentName:
Type: String
Default: customer-support-agent
FoundationModel:
Type: String
Default: anthropic.claude-v3:5
Mappings:
EnvironmentConfig:
dev:
IdleTTL: 1800
AutoPrepare: true
staging:
IdleTTL: 1800
AutoPrepare: true
production:
IdleTTL: 3600
AutoPrepare: true
Conditions:
IsProduction: !Equals [!Ref Environment, production]
Resources:
# Agent Resource Role
AgentResourceRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-agent-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-agent-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/*"
- Effect: Allow
Action:
- bedrock:Retrieve
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:knowledge-base/*"
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource: !GetAtt ActionGroupFunction.Arn
# Action Group Lambda Function
ActionGroupFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-action-group"
Runtime: python3.11
Handler: handler.handler
Code:
S3Bucket: !Ref CodeBucket
S3Key: lambda/action-group.zip
Timeout: 30
Role: !GetAtt LambdaExecutionRole.Arn
# Lambda Execution Role
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-lambda-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
# OpenSearch Serverless Collection
OpenSearchCollection:
Type: AWS::OpenSearchServerless::Collection
Properties:
Name: !Sub "${AWS::StackName}-kb-collection"
Type: SEARCH
# Access Policy for OpenSearch
OpenSearchAccessPolicy:
Type: AWS::OpenSearchServerless::AccessPolicy
Properties:
Name: !Sub "${AWS::StackName}-aoss-access"
Policy: !Sub |
[
{
"Rules": [
{
"Resource": ["collection/${OpenSearchCollection.id}"],
"Permission": ["aoss:*"]
},
{
"Resource": ["index/collection/${OpenSearchCollection.id}/*"],
"Permission": ["aoss:*"]
}
],
"Principal": ["${AgentResourceRole.Arn}"]
}
]
Type: data
# Security Policy for OpenSearch
OpenSearchSecurityPolicy:
Type: AWS::OpenSearchServerless::SecurityPolicy
Properties:
Name: !Sub "${AWS::StackName}-aoss-security"
Policy: !Sub |
{
"Rules": [
{
"Resource": ["collection/${OpenSearchCollection.id}"],
"ResourceType": "collection"
}
],
"Principal": ["*"]
}
Type: encryption
# Knowledge Base Role
KnowledgeBaseRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-kb-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-kb-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- aoss:APIAccessAll
Resource: !GetAtt OpenSearchCollection.Arn
- Effect: Allow
Action:
- s3:GetObject
Resource: !Sub "${DocumentBucket.Arn}/*"
# Knowledge Base
SupportKnowledgeBase:
Type: AWS::Bedrock::KnowledgeBase
Properties:
KnowledgeBaseName: !Sub "${AWS::StackName}-support-kb"
Description: Knowledge base for customer support
EmbeddingModelArn: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/amazon.titan-embed-text-v1"
KnowledgeBaseConfiguration:
Type: VECTOR
VectorKnowledgeBaseConfiguration:
VectorStoreConfiguration:
OpensearchServerlessConfiguration:
CollectionArn: !GetAtt OpenSearchCollection.Arn
VectorIndexName: kb-index
FieldMapping:
VectorField: vector
TextField: text
MetadataField: metadata
RoleArn: !GetAtt KnowledgeBaseRole.Arn
# Knowledge Base Data Source
KnowledgeBaseDataSource:
Type: AWS::Bedrock::DataSource
Properties:
KnowledgeBaseId: !Ref SupportKnowledgeBase
DataSourceName: !Sub "${AWS::StackName}-s3-ds"
Description: S3 data source for support documents
DataSourceConfiguration:
S3Configuration:
BucketArn: !Ref DocumentBucket
InclusionPrefixes:
- support/
- faq/
- policies/
VectorIngestionConfiguration:
ChunkingConfiguration:
ChunkingStrategy: FIXED_SIZE
FixedSizeChunking:
MaxTokens: 512
OverlapPercentage: 20
# Document Bucket
DocumentBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "${AWS::StackName}-documents-${AWS::AccountId}-${AWS::Region}"
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
VersioningConfiguration:
Status: Enabled
# API Schema Bucket
ApiSchemaBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "${AWS::StackName}-schema-${AWS::AccountId}-${AWS::Region}"
# Bedrock Agent
CustomerSupportAgent:
Type: AWS::Bedrock::Agent
Properties:
AgentName: !Sub "${AgentName}-${Environment}"
Description: Customer support agent with knowledge base
FoundationModel: !Ref FoundationModel
AgentResourceRoleArn: !GetAtt AgentResourceRole.Arn
IdleSessionTTLInSeconds: !FindInMap [EnvironmentConfig, !Ref Environment, IdleTTL]
AutoPrepare: !FindInMap [EnvironmentConfig, !Ref Environment, AutoPrepare]
KnowledgeBases:
- KnowledgeBaseId: !Ref SupportKnowledgeBase
Description: Support documentation knowledge base
# Action Group
ApiActionGroup:
Type: AWS::Bedrock::AgentActionGroup
Properties:
AgentId: !Ref CustomerSupportAgent
AgentVersion: DRAFT
ActionGroupName: CustomerActions
Description: Action group for customer operations
ActionGroupExecutor:
Lambda: !GetAtt ActionGroupFunction.Arn
ApiSchema:
S3:
S3BucketName: !Ref ApiSchemaBucket
S3ObjectKey: api-schema.json
Outputs:
AgentId:
Description: ID of the Bedrock agent
Value: !GetAtt CustomerSupportAgent.AgentId
Export:
Name: !Sub "${AWS::StackName}-AgentId"
AgentAliasId:
Description: Alias ID of the Bedrock agent
Value: !GetAtt CustomerSupportAgent.LatestAgentAliasId
Export:
Name: !Sub "${AWS::StackName}-AgentAliasId"
AgentArn:
Description: ARN of the Bedrock agent
Value: !GetAtt CustomerSupportAgent.AgentArn
Export:
Name: !Sub "${AWS::StackName}-AgentArn"
KnowledgeBaseId:
Description: ID of the knowledge base
Value: !GetAtt SupportKnowledgeBase.KnowledgeBaseId
Export:
Name: !Sub "${AWS::StackName}-KnowledgeBaseId"Example 2: Guardrail with Comprehensive Content Moderation
Complete guardrail implementation with topic policy, content filters, and sensitive information protection.
AWSTemplateFormatVersion: 2010-09-09
Description: Comprehensive guardrail for content moderation
Parameters:
Environment:
Type: String
Default: production
Resources:
# Guardrail for content moderation
ContentGuardrail:
Type: AWS::Bedrock::Guardrail
Properties:
GuardrailName: !Sub "${AWS::StackName}-guardrail"
Description: Comprehensive content moderation guardrail
# Topic Policy - Block sensitive topics
TopicPolicy:
Topics:
- Name: MedicalDiagnosis
Definition: Providing medical diagnosis or treatment recommendations
Examples:
- "What could be causing my headache?"
- "Do I need to see a doctor for this?"
- "What medication should I take?"
Type: DENIED
- Name: LegalAdvice
Definition: Providing legal advice or representation recommendations
Examples:
- "Can I sue my employer?"
- "What are my legal rights in this situation?"
- "Should I get a lawyer?"
Type: DENIED
- Name: FinancialInvestment
Definition: Personalized financial investment recommendations
Examples:
- "What stocks should I buy?"
- "Is crypto a good investment?"
- "Should I move my 401k?"
Type: DENIED
- Name: HazardousActivities
Definition: Instructions for dangerous or illegal activities
Examples:
- "How to make a weapon"
- "How to hack someone's account"
Type: DENIED
# Content Policy - Filter harmful content
ContentPolicy:
Filters:
- Type: PROFANITY
InputStrength: LOW
OutputStrength: LOW
- Type: HATE
InputStrength: MEDIUM
OutputStrength: HIGH
- Type: SEXUAL
InputStrength: LOW
OutputStrength: MEDIUM
- Type: VIOLENCE
InputStrength: MEDIUM
OutputStrength: HIGH
- Type: HARASSMENT
InputStrength: MEDIUM
OutputStrength: HIGH
# Word Policy - Custom blocked words
WordPolicy:
Words:
- Text: "offensive-term-1"
InputAction: BLOCK
OutputAction: BLOCK
- Text: "offensive-term-2"
InputAction: MASK
OutputAction: MASK
ManagedWordLists:
- Type: PROFANITY
# Sensitive Information Policy - PII protection
SensitiveInformationPolicy:
PiiEntities:
- Name: EMAIL
Action: MASK
- Name: PHONE_NUMBER
Action: MASK
- Name: SSN
Action: BLOCK
- Name: CREDIT_DEBIT_NUMBER
Action: BLOCK
- Name: BANK_ACCOUNT_NUMBER
Action: BLOCK
- Name: IP_ADDRESS
Action: MASK
- Name: DATE_OF_BIRTH
Action: MASK
- Name: DRIVERS_LICENSE
Action: BLOCK
- Name: PASSPORT
Action: BLOCK
Regexes:
- Name: CustomApiKeyPattern
Pattern: "(api|secret|key)-[a-zA-Z0-9]{32}"
Action: BLOCK
- Name: PrivateKeyPattern
Pattern: "-----BEGIN PRIVATE KEY-----"
Action: BLOCK
# Contextual Grounding Policy
ContextualGroundingPolicy:
Filters:
- Type: GROUNDING
Threshold: 0.7
- Type: RELEVANCE
Threshold: 0.7
# Guardrail Version
GuardrailVersion:
Type: AWS::Bedrock::GuardrailVersion
Properties:
GuardrailId: !Ref ContentGuardrail
Description: Production version of the guardrail
Outputs:
GuardrailId:
Description: ID of the guardrail
Value: !Ref ContentGuardrail
Export:
Name: !Sub "${AWS::StackName}-GuardrailId"
GuardrailVersion:
Description: Version of the guardrail
Value: !GetAtt GuardrailVersion.GuardrailVersion
Export:
Name: !Sub "${AWS::StackName}-GuardrailVersion"
GuardrailArn:
Description: ARN of the guardrail
Value: !GetAtt ContentGuardrail.GuardrailArn
Export:
Name: !Sub "${AWS::StackName}-GuardrailArn"Example 3: Knowledge Base with Multiple Data Sources
Knowledge base with S3 and web crawl data sources.
AWSTemplateFormatVersion: 2010-09-09
Description: Knowledge base with multiple data sources
Parameters:
Environment:
Type: String
Default: dev
Resources:
# OpenSearch Collection
VectorCollection:
Type: AWS::OpenSearchServerless::Collection
Properties:
Name: !Sub "${AWS::StackName}-kb-collection"
Type: SEARCH
# Access Policy
AccessPolicy:
Type: AWS::OpenSearchServerless::AccessPolicy
Properties:
Name: !Sub "${AWS::StackName}-access"
Policy: !Sub |
[
{
"Rules": [
{
"Resource": ["collection/${VectorCollection.id}"],
"Permission": ["aoss:*"]
}
],
"Principal": ["${KnowledgeBaseRole.Arn}"]
}
]
Type: data
# Knowledge Base Role
KnowledgeBaseRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-kb-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-kb-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- aoss:APIAccessAll
Resource: !GetAtt VectorCollection.Arn
- Effect: Allow
Action:
- s3:GetObject
- s3:ListBucket
Resource:
- !Ref DocumentsBucket
- !Sub "${DocumentsBucket.Arn}/*"
# Knowledge Base
ProductKnowledgeBase:
Type: AWS::Bedrock::KnowledgeBase
Properties:
KnowledgeBaseName: !Sub "${AWS::StackName}-product-kb"
Description: Product documentation knowledge base
EmbeddingModelArn: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/amazon.titan-embed-text-v1"
KnowledgeBaseConfiguration:
Type: VECTOR
VectorKnowledgeBaseConfiguration:
VectorStoreConfiguration:
OpensearchServerlessConfiguration:
CollectionArn: !GetAtt VectorCollection.Arn
VectorIndexName: product-kb-index
FieldMapping:
VectorField: vector
TextField: text
MetadataField: metadata
RoleArn: !GetAtt KnowledgeBaseRole.Arn
# S3 Data Source - Documents
S3DataSource:
Type: AWS::Bedrock::DataSource
Properties:
KnowledgeBaseId: !Ref ProductKnowledgeBase
DataSourceName: !Sub "${AWS::StackName}-s3-ds"
Description: S3 data source for product documents
DataSourceConfiguration:
S3Configuration:
BucketArn: !Ref DocumentsBucket
InclusionPrefixes:
- product-docs/
- user-guides/
- api-reference/
ExclusionPrefixes:
- archive/
- temp/
VectorIngestionConfiguration:
ChunkingConfiguration:
ChunkingStrategy: FIXED_SIZE
FixedSizeChunking:
MaxTokens: 1000
OverlapPercentage: 10
# S3 Data Source - Knowledge Articles
KnowledgeArticlesDataSource:
Type: AWS::Bedrock::DataSource
Properties:
KnowledgeBaseId: !Ref ProductKnowledgeBase
DataSourceName: !Sub "${AWS::StackName}-articles-ds"
Description: S3 data source for knowledge articles
DataSourceConfiguration:
S3Configuration:
BucketArn: !Ref ArticlesBucket
InclusionPrefixes:
- articles/
VectorIngestionConfiguration:
ChunkingConfiguration:
ChunkingStrategy: HIERARCHICAL
HierarchicalChunking:
Level1MaxTokens: 2000
Level2MaxTokens: 500
OverlapTokens: 100
# Web Data Source - Documentation Website
WebDataSource:
Type: AWS::Bedrock::DataSource
Properties:
KnowledgeBaseId: !Ref ProductKnowledgeBase
DataSourceName: !Sub "${AWS::StackName}-web-ds"
Description: Web data source for online documentation
DataSourceConfiguration:
WebConfiguration:
SourceUrl: "https://docs.example.com"
CrawlScope: HOST_ONLY
InclusionFilters:
- "https://docs.example.com/*"
ExtractionEngine: BEDROCK_FAST_CHUNKER
VectorIngestionConfiguration:
ChunkingConfiguration:
ChunkingStrategy: FIXED_SIZE
FixedSizeChunking:
MaxTokens: 512
OverlapPercentage: 15
# Documents Bucket
DocumentsBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "${AWS::StackName}-documents-${AWS::AccountId}-${AWS::Region}"
# Articles Bucket
ArticlesBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "${AWS::StackName}-articles-${AWS::AccountId}-${AWS::Region}"
Outputs:
KnowledgeBaseId:
Description: ID of the knowledge base
Value: !Ref ProductKnowledgeBase
KnowledgeBaseArn:
Description: ARN of the knowledge base
Value: !GetAtt ProductKnowledgeBase.KnowledgeBaseArnExample 4: Bedrock Flow for Multi-Turn Conversation
Flow with classifier, knowledge base, and Lambda nodes for complex conversation handling.
AWSTemplateFormatVersion: 2010-09-09
Description: Bedrock Flow for multi-turn conversation handling
Parameters:
Environment:
Type: String
Default: dev
Resources:
# Flow Execution Role
FlowRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-flow-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-flow-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/*"
- Effect: Allow
Action:
- bedrock:Retrieve
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:knowledge-base/*"
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- !GetAtt OrderStatusFunction.Arn
- !GetAtt ProductLookupFunction.Arn
# Order Status Lambda
OrderStatusFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-order-status"
Runtime: python3.11
Handler: handler.check_status
Code:
S3Bucket: !Ref CodeBucket
S3Key: lambda/order-status.zip
Role: !GetAtt LambdaBasicRole.Arn
# Product Lookup Lambda
ProductLookupFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-product-lookup"
Runtime: python3.11
Handler: handler.lookup_product
Code:
S3Bucket: !Ref CodeBucket
S3Key: lambda/product-lookup.zip
Role: !GetAtt LambdaBasicRole.Arn
# Lambda Basic Role
LambdaBasicRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
# Processing Flow
CustomerServiceFlow:
Type: AWS::Bedrock::Flow
Properties:
Name: !Sub "${AWS::StackName}-customer-service"
Description: Multi-turn customer service flow
ExecutionRoleArn: !GetAtt FlowRole.Arn
Definition:
StartAt: IntentClassifier
Nodes:
# Classifier Node - Routes to appropriate handler
IntentClassifier:
Type: Classifier
Name: IntentClassifier
Description: Classifies customer intent
Configuration:
BedrockClassifierConfiguration:
BedrockFoundationModelConfiguration:
ModelId: anthropic.claude-v3:5
InferenceConfiguration:
Temperature: 0.0
MaxTokens: 500
InputConfiguration:
TextInput:
Name: user_input
OutputConfiguration:
StructuredOutput:
Name: intent
Description: Classified intent
JsonOutputSchema:
properties:
intent:
type: string
enum:
- order_status
- product_info
- return_request
- account_update
- general_inquiry
confidence:
type: number
entities:
type: array
Transitions:
Next:
OrderStatus: intent.order_status
ProductInfo: intent.product_info
ReturnRequest: intent.return_request
AccountUpdate: intent.account_update
GeneralInquiry: "*"
# Order Status Node
OrderStatus:
Type: LambdaFunction
Name: OrderStatusHandler
Description: Checks order status
Configuration:
LambdaConfiguration:
LambdaArn: !GetAtt OrderStatusFunction.Arn
Input:
text: "{{user_input}}"
Output:
Name: order_result
Transitions:
Next: ResponseFormatter
# Product Info Node - Uses Knowledge Base
ProductInfo:
Type: KnowledgeBase
Name: ProductKnowledgeBase
Description: Retrieves product information
Configuration:
KnowledgeBaseConfiguration:
KnowledgeBaseId: !Ref ProductKnowledgeBase
ModelId: anthropic.claude-v3:5
RetrievalConfiguration:
VectorSearchConfiguration:
NumberOfResults: 5
Transitions:
Next: ResponseFormatter
# Return Request Node
ReturnRequest:
Type: LambdaFunction
Name: ReturnRequestHandler
Description: Processes return requests
Configuration:
LambdaConfiguration:
LambdaArn: !GetAtt OrderStatusFunction.Arn
Input:
text: "{{user_input}}"
Output:
Name: return_result
Transitions:
Next: ResponseFormatter
# Account Update Node
AccountUpdate:
Type: Model
Name: AccountUpdater
Description: Handles account updates
Configuration:
BedrockModelConfiguration:
ModelId: anthropic.claude-v3:5
InferenceConfiguration:
Temperature: 0.3
MaxTokens: 1000
System:
- Text: "You are handling a customer account update request. Gather necessary information and confirm changes."
Transitions:
Next: ResponseFormatter
# General Inquiry Node
GeneralInquiry:
Type: Model
Name: GeneralAssistant
Description: Answers general questions
Configuration:
BedrockModelConfiguration:
ModelId: anthropic.claude-v3:5
InferenceConfiguration:
Temperature: 0.7
MaxTokens: 1500
Transitions:
Next: ResponseFormatter
# Response Formatter Node
ResponseFormatter:
Type: Model
Name: ResponseFormatter
Description: Formats the final response
Configuration:
BedrockModelConfiguration:
ModelId: anthropic.claude-v3:5
InferenceConfiguration:
Temperature: 0.5
MaxTokens: 2000
System:
- Text: "You are a customer service response formatter. Provide a clear, helpful, and concise response to the customer."
Transitions:
Next: ResponseValidator
# Response Validator Node
ResponseValidator:
Type: Model
Name: ResponseValidator
Description: Validates response before sending
Configuration:
BedrockModelConfiguration:
ModelId: anthropic.claude-v3:5
InferenceConfiguration:
Temperature: 0.0
MaxTokens: 500
Transitions:
Next:
SendResponse: "*"
RetryFormatting: ResponseFormatter
IsEnd: true
Outputs:
FlowId:
Description: ID of the flow
Value: !Ref CustomerServiceFlow
FlowArn:
Description: ARN of the flow
Value: !GetAtt CustomerServiceFlow.ArnExample 5: Application Inference Profile
Inference profile for optimized multi-model access.
AWSTemplateFormatVersion: 2010-09-09
Description: Application inference profile for optimized model access
Parameters:
ProfileName:
Type: String
Default: production-profile
Environment:
Type: String
Default: production
Mappings:
ModelConfig:
dev:
Temperature: 0.9
MaxTokens: 4096
staging:
Temperature: 0.7
MaxTokens: 4096
production:
Temperature: 0.5
MaxTokens: 8192
Resources:
# Application Inference Profile
ProductionInferenceProfile:
Type: AWS::Bedrock::ApplicationInferenceProfile
Properties:
ApplicationInferenceProfileName: !Sub "${ProfileName}-${Environment}"
Description: Production inference profile for customer service
ModelSource:
CopyFrom: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:application-inference-profile/*"
InferenceConfiguration:
Text:
anthropic.claude-v3:5:
Temperature: !FindInMap [ModelConfig, !Ref Environment, Temperature]
MaxTokens: !FindInMap [ModelConfig, !Ref Environment, MaxTokens]
TopP: 0.999
StopSequences:
- "\n\nHuman:"
anthropic.claude-sonnet-4-20250514:
Temperature: !FindInMap [ModelConfig, !Ref Environment, Temperature]
MaxTokens: !FindInMap [ModelConfig, !Ref Environment, MaxTokens]
TopP: 0.999
Outputs:
InferenceProfileId:
Description: ID of the inference profile
Value: !Ref ProductionInferenceProfile
InferenceProfileArn:
Description: ARN of the inference profile
Value: !GetAtt ProductionInferenceProfile.ArnExample 6: Agent with Guardrail Integration
Bedrock agent with integrated guardrail for safe interactions.
AWSTemplateFormatVersion: 2010-09-09
Description: Bedrock agent with guardrail integration
Parameters:
Environment:
Type: String
Default: production
Resources:
# Agent Resource Role with Guardrail permissions
AgentResourceRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-agent-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-agent-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/*"
- Effect: Allow
Action:
- bedrock:ApplyGuardrail
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:guardrail/*"
# Guardrail for content moderation
SafetyGuardrail:
Type: AWS::Bedrock::Guardrail
Properties:
GuardrailName: !Sub "${AWS::StackName}-safety"
Description: Safety guardrail for agent interactions
TopicPolicy:
Topics:
- Name: DangerousContent
Definition: Content promoting harm or illegal activities
Type: DENIED
ContentPolicy:
Filters:
- Type: PROFANITY
InputStrength: LOW
OutputStrength: LOW
- Type: HATE
InputStrength: MEDIUM
OutputStrength: HIGH
- Type: VIOLENCE
InputStrength: MEDIUM
OutputStrength: HIGH
WordPolicy:
ManagedWordLists:
- Type: PROFANITY
SensitiveInformationPolicy:
PiiEntities:
- Name: EMAIL
Action: MASK
- Name: SSN
Action: BLOCK
# Guardrail Version
GuardrailVersion:
Type: AWS::Bedrock::GuardrailVersion
Properties:
GuardrailId: !Ref SafetyGuardrail
Description: Version 1 of safety guardrail
# Bedrock Agent
SafeAgent:
Type: AWS::Bedrock::Agent
Properties:
AgentName: !Sub "${AWS::StackName}-safe-agent"
Description: Safe agent with guardrail protection
FoundationModel: anthropic.claude-v3:5
AgentResourceRoleArn: !GetAtt AgentResourceRole.Arn
IdleSessionTTLInSeconds: 1800
AutoPrepare: true
# Agent Alias with Guardrail
SafeAgentAlias:
Type: AWS::Bedrock::AgentAlias
Properties:
AgentId: !Ref SafeAgent
AgentAliasName: production
Description: Production alias with guardrail
RoutingConfiguration:
- AgentVersion: DRAFT
# Note: Guardrails are applied during runtime via the ApplyGuardrail API
# The guardrail is not directly attached to the agent resource
# but is used in the application code when invoking the agent
Outputs:
AgentId:
Description: ID of the agent
Value: !Ref SafeAgent
AgentAliasId:
Description: ID of the agent alias
Value: !Ref SafeAgentAlias
GuardrailId:
Description: ID of the guardrail
Value: !Ref SafetyGuardrail
GuardrailArn:
Description: ARN of the guardrail
Value: !GetAtt SafetyGuardrail.GuardrailArnExample 7: Prompt Management with Versions
Bedrock Prompt resource with multiple variants and versions.
AWSTemplateFormatVersion: 2010-09-09
Description: Bedrock Prompt with multiple variants
Parameters:
Environment:
Type: String
Default: dev
Mappings:
Config:
dev:
Temperature: 0.9
MaxTokens: 2048
staging:
Temperature: 0.7
MaxTokens: 4096
production:
Temperature: 0.5
MaxTokens: 4096
Resources:
# Customer Support Prompt
CustomerSupportPrompt:
Type: AWS::Bedrock::Prompt
Properties:
Name: !Sub "${AWS::StackName}-support-prompt"
Description: Customer support prompt with multiple variants
DefaultVariant: empathetic
Variants:
# Empathetic Variant
- Name: empathetic
Description: Empathetic and understanding tone
Text: |
You are a highly empathetic customer support agent. Your goal is to:
1. Acknowledge the customer's feelings and concerns with genuine empathy
2. Listen actively to understand their full situation
3. Provide clear, actionable solutions
4. Follow up to ensure satisfaction
Customer message: {{customer_message}}
Conversation history: {{conversation_history}}
Respond with empathy, using phrases like "I understand how frustrating this must be" and "I appreciate your patience".
InferenceConfiguration:
Temperature: !FindInMap [Config, !Ref Environment, Temperature]
MaxTokens: !FindInMap [Config, !Ref Environment, MaxTokens]
# Professional Variant
- Name: professional
Description: Professional and efficient tone
Text: |
You are a professional customer support agent. Your goal is to:
1. Address the customer's issue efficiently
2. Provide accurate information
3. Offer clear next steps
4. Maintain a courteous tone
Customer message: {{customer_message}}
Conversation history: {{conversation_history}}
Respond in a professional manner with clear, concise language.
InferenceConfiguration:
Temperature: 0.3
MaxTokens: 2048
TopP: 0.9
# Technical Variant
- name: technical
Description: Technical support focused tone
Text: |
You are a technical support specialist. Your goal is to:
1. Understand the technical issue in detail
2. Provide step-by-step troubleshooting
3. Include relevant technical information
4. Suggest preventive measures
Customer message: {{customer_message}}
System information: {{system_info}}
Error logs: {{error_logs}}
Respond with detailed technical information and clear instructions.
InferenceConfiguration:
Temperature: 0.2
MaxTokens: 4096
Outputs:
PromptId:
Description: ID of the prompt
Value: !Ref CustomerSupportPrompt
PromptArn:
Description: ARN of the prompt
Value: !GetAtt CustomerSupportPrompt.ArnExample 8: Complete RAG Implementation with Cross-Stack References
Multi-stack architecture with separate network, data, and application stacks.
# Stack 1: Network and Infrastructure Stack
AWSTemplateFormatVersion: 2010-09-09
Description: Network infrastructure for Bedrock resources
Resources:
# OpenSearch Serverless Collection
VectorCollection:
Type: AWS::OpenSearchServerless::Collection
Properties:
Name: !Sub "${AWS::StackName}-vector-collection"
Type: SEARCH
# Access Policy
VectorAccessPolicy:
Type: AWS::OpenSearchServerless::AccessPolicy
Properties:
Name: !Sub "${AWS::StackName}-vector-access"
Policy: !Sub |
[
{
"Rules": [
{
"Resource": ["collection/${VectorCollection.id}"],
"Permission": ["aoss:*"]
}
],
"Principal": ["*"]
}
]
Type: data
Outputs:
VectorCollectionArn:
Description: ARN of the vector collection
Value: !GetAtt VectorCollection.Arn
Export:
Name: !Sub "${AWS::StackName}-VectorCollectionArn"
VectorCollectionEndpoint:
Description: Endpoint of the vector collection
Value: !GetAtt VectorCollection.Endpoint
Export:
Name: !Sub "${AWS::StackName}-VectorCollectionEndpoint"# Stack 2: Data Stack - Knowledge Base
AWSTemplateFormatVersion: 2010-09-09
Description: Knowledge base stack
Parameters:
NetworkStackName:
Type: String
Default: bedrock-network
Environment:
Type: String
Default: dev
Resources:
# Knowledge Base Role
KnowledgeBaseRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-kb-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-kb-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- aoss:APIAccessAll
Resource: !ImportValue
!Sub "${NetworkStackName}-VectorCollectionArn"
- Effect: Allow
Action:
- s3:GetObject
- s3:ListBucket
Resource:
- !Ref DocumentBucket
- !Sub "${DocumentBucket.Arn}/*"
# Knowledge Base
KnowledgeBase:
Type: AWS::Bedrock::KnowledgeBase
Properties:
KnowledgeBaseName: !Sub "${AWS::StackName}-kb-${Environment}"
Description: Knowledge base for RAG
EmbeddingModelArn: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/amazon.titan-embed-text-v1"
KnowledgeBaseConfiguration:
Type: VECTOR
VectorKnowledgeBaseConfiguration:
VectorStoreConfiguration:
OpensearchServerlessConfiguration:
CollectionArn: !ImportValue
!Sub "${NetworkStackName}-VectorCollectionArn"
VectorIndexName: kb-index
FieldMapping:
VectorField: vector
TextField: text
MetadataField: metadata
RoleArn: !GetAtt KnowledgeBaseRole.Arn
# Data Source
DataSource:
Type: AWS::Bedrock::DataSource
Properties:
KnowledgeBaseId: !Ref KnowledgeBase
DataSourceName: !Sub "${AWS::StackName}-ds"
DataSourceConfiguration:
S3Configuration:
BucketArn: !Ref DocumentBucket
VectorIngestionConfiguration:
ChunkingConfiguration:
ChunkingStrategy: FIXED_SIZE
FixedSizeChunking:
MaxTokens: 512
OverlapPercentage: 20
# Document Bucket
DocumentBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "${AWS::StackName}-documents-${AWS::AccountId}-${AWS::Region}"
Outputs:
KnowledgeBaseId:
Description: ID of the knowledge base
Value: !Ref KnowledgeBase
Export:
Name: !Sub "${AWS::StackName}-KnowledgeBaseId"
KnowledgeBaseArn:
Description: ARN of the knowledge base
Value: !GetAtt KnowledgeBase.KnowledgeBaseArn
Export:
Name: !Sub "${AWS::StackName}-KnowledgeBaseArn"# Stack 3: Application Stack - Agent
AWSTemplateFormatVersion: 2010-09-09
Description: Application stack with Bedrock agent
Parameters:
DataStackName:
Type: String
Default: bedrock-data
Environment:
Type: String
Default: dev
Resources:
# Agent Resource Role
AgentResourceRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-agent-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: bedrock.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: !Sub "${AWS::StackName}-agent-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
Resource: "*"
- Effect: Allow
Action:
- bedrock:Retrieve
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:knowledge-base/*"
# Bedrock Agent with Knowledge Base
RAGAgent:
Type: AWS::Bedrock::Agent
Properties:
AgentName: !Sub "${AWS::StackName}-agent-${Environment}"
Description: RAG-enabled agent
FoundationModel: anthropic.claude-v3:5
AgentResourceRoleArn: !GetAtt AgentResourceRole.Arn
AutoPrepare: true
KnowledgeBases:
- KnowledgeBaseId: !ImportValue
!Sub "${DataStackName}-KnowledgeBaseId"
Description: Knowledge base for RAG
# Agent Alias
AgentAlias:
Type: AWS::Bedrock::AgentAlias
Properties:
AgentId: !Ref RAGAgent
AgentAliasName: !Ref Environment
Description: Alias for environment
RoutingConfiguration:
- AgentVersion: DRAFT
Outputs:
AgentId:
Description: ID of the agent
Value: !Ref RAGAgent
Export:
Name: !Sub "${AWS::StackName}-AgentId"
AgentAliasId:
Description: ID of the agent alias
Value: !Ref AgentAlias
Export:
Name: !Sub "${AWS::StackName}-AgentAliasId"
AgentArn:
Description: ARN of the agent
Value: !GetAtt RAGAgent.AgentArn
Export:
Name: !Sub "${AWS::StackName}-AgentArn"AWS CloudFormation Bedrock - Reference
This reference guide contains detailed information about AWS CloudFormation resources, intrinsic functions, and configurations for Amazon Bedrock infrastructure.
AWS::Bedrock::Agent
Creates a Bedrock agent that can be used to build AI-powered applications with conversational capabilities.
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| AgentName | String | Yes | The name of the agent |
| Description | String | No | Description of the agent's purpose |
| FoundationModel | String | Yes | The foundation model to use |
| AgentResourceRoleArn | String | Yes | ARN of the IAM role for the agent |
| IdleSessionTTLInSeconds | Integer | No | Session timeout in seconds (300-3600) |
| AutoPrepare | Boolean | No | Whether to auto-prepare the agent |
| KnowledgeBases | List of KnowledgeBaseConfig | No | Knowledge bases to associate |
| ActionGroups | List of ActionGroupConfig | No | Action groups to configure |
KnowledgeBaseConfig Structure
| Property | Type | Required | Description |
|---|---|---|---|
| KnowledgeBaseId | String | Yes | ID of the knowledge base |
| Description | String | No | Description of the knowledge base |
ActionGroupConfig Structure
| Property | Type | Required | Description |
|---|---|---|---|
| ActionGroupName | String | Yes | Name of the action group |
| Description | String | No | Description of the action group |
| ActionGroupExecutor | ActionGroupExecutor | No | Executor configuration |
| ApiSchema | ApiSchema | No | API schema for the action group |
| SkipModelsInExecution | Boolean | No | Whether to skip model execution |
ActionGroupExecutor Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Lambda | String | Yes | Lambda function ARN |
| Custom | String | No | Custom executor ARN |
ApiSchema Structure
| Property | Type | Required | Description |
|---|---|---|---|
| S3 | S3Location | No | S3 location of the schema |
| Payload | Json | No | Inline OpenAPI schema |
S3Location Structure
| Property | Type | Required | Description |
|---|---|---|---|
| S3BucketName | String | Yes | S3 bucket name |
| S3ObjectKey | String | Yes | S3 object key |
Example
Resources:
MyAgent:
Type: AWS::Bedrock::Agent
Properties:
AgentName: !Sub "${AWS::StackName}-support-agent"
Description: Agent for customer support
FoundationModel: anthropic.claude-v3:5
AgentResourceRoleArn: !GetAtt AgentRole.Arn
AutoPrepare: true
IdleSessionTTLInSeconds: 1800Attributes
| Attribute | Description |
|---|---|
| AgentId | The ID of the agent |
| AgentName | The name of the agent |
| AgentArn | The ARN of the agent |
| LatestAgentAliasId | The latest alias ID of the agent |
AWS::Bedrock::AgentAlias
Creates an alias for a Bedrock agent for versioning and deployment.
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| AgentId | String | Yes | ID of the agent |
| AgentAliasName | String | Yes | Name of the alias |
| Description | String | No | Description of the alias |
| RoutingConfiguration | List of RoutingConfiguration | No | Routing configuration |
RoutingConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| AgentVersion | String | Yes | Agent version to route to |
| AgentVariant | String | No | Variant of the agent |
Example
Resources:
AgentAlias:
Type: AWS::Bedrock::AgentAlias
Properties:
AgentId: !Ref MyAgent
AgentAliasName: production
Description: Production alias
RoutingConfiguration:
- AgentVersion: 2Attributes
| Attribute | Description |
|---|---|
| AgentAliasId | The ID of the agent alias |
| AgentAliasArn | The ARN of the agent alias |
AWS::Bedrock::AgentActionGroup
Configures an action group for a Bedrock agent.
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| AgentId | String | Yes | ID of the agent |
| AgentVersion | String | Yes | Version of the agent (DRAFT or version number) |
| ActionGroupName | String | Yes | Name of the action group |
| Description | String | No | Description of the action group |
| ActionGroupExecutor | ActionGroupExecutor | Yes | Executor for the action group |
| ApiSchema | ApiSchema | Yes | API schema for the action group |
| SkipModelsInExecution | Boolean | No | Whether to skip model execution |
Example
Resources:
MyActionGroup:
Type: AWS::Bedrock::AgentActionGroup
Properties:
AgentId: !Ref MyAgent
AgentVersion: DRAFT
ActionGroupName: ApiActionGroup
Description: API action group
ActionGroupExecutor:
Lambda: !Ref ActionGroupFunction
ApiSchema:
S3:
S3BucketName: !Ref SchemaBucket
S3ObjectKey: api-schema.jsonAWS::Bedrock::KnowledgeBase
Creates a knowledge base for Retrieval-Augmented Generation (RAG).
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| KnowledgeBaseName | String | Yes | Name of the knowledge base |
| Description | String | No | Description of the knowledge base |
| EmbeddingModelArn | String | Yes | ARN of the embedding model |
| KnowledgeBaseConfiguration | KnowledgeBaseConfiguration | Yes | Configuration for the knowledge base |
| RoleArn | String | Yes | ARN of the IAM role |
KnowledgeBaseConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Type | String | Yes | Type of knowledge base (VECTOR) |
| VectorKnowledgeBaseConfiguration | VectorKnowledgeBaseConfiguration | Yes | Vector store configuration |
VectorKnowledgeBaseConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| VectorStoreConfiguration | VectorStoreConfiguration | Yes | Vector store configuration |
VectorStoreConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| OpensearchServerlessConfiguration | OpensearchServerlessConfiguration | Cond | OpenSearch Serverless config |
| PineconeConfiguration | PineconeConfiguration | Cond | Pinecone config |
| PgvectorConfiguration | PgvectorConfiguration | Cond | pgvector config |
| RedisEnterpriseCloudConfiguration | RedisEnterpriseCloudConfiguration | Cond | Redis config |
OpensearchServerlessConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| CollectionArn | String | Yes | ARN of the OpenSearch collection |
| VectorIndexName | String | Yes | Name of the vector index |
| FieldMapping | FieldMapping | Yes | Field mapping configuration |
FieldMapping Structure
| Property | Type | Required | Description |
|---|---|---|---|
| VectorField | String | Yes | Name of the vector field |
| TextField | String | Yes | Name of the text field |
| MetadataField | String | Yes | Name of the metadata field |
PineconeConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| ConnectionString | String | Yes | Pinecone connection string |
| CredentialsSecretArn | String | Yes | ARN of the secret with credentials |
| Namespace | String | No | Pinecone namespace |
| FieldMapping | PineconeFieldMapping | Yes | Field mapping configuration |
PineconeFieldMapping Structure
| Property | Type | Required | Description |
|---|---|---|---|
| TextField | String | Yes | Name of the text field |
| MetadataField | String | Yes | Name of the metadata field |
PgvectorConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| ConnectionString | String | Yes | PostgreSQL connection string |
| TableName | String | Yes | Name of the table |
| ColumnName | String | Yes | Name of the vector column |
| FieldMapping | FieldMapping | Yes | Field mapping configuration |
Example
Resources:
MyKnowledgeBase:
Type: AWS::Bedrock::KnowledgeBase
Properties:
KnowledgeBaseName: !Sub "${AWS::StackName}-kb"
Description: Knowledge base for documents
EmbeddingModelArn: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/amazon.titan-embed-text-v1"
KnowledgeBaseConfiguration:
Type: VECTOR
VectorKnowledgeBaseConfiguration:
VectorStoreConfiguration:
OpensearchServerlessConfiguration:
CollectionArn: !GetAtt Collection.Arn
VectorIndexName: kb-index
FieldMapping:
VectorField: vector
TextField: text
MetadataField: metadata
RoleArn: !GetAtt KnowledgeBaseRole.ArnAttributes
| Attribute | Description |
|---|---|
| KnowledgeBaseId | The ID of the knowledge base |
| KnowledgeBaseArn | The ARN of the knowledge base |
AWS::Bedrock::DataSource
Creates a data source for a knowledge base.
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| KnowledgeBaseId | String | Yes | ID of the knowledge base |
| DataSourceName | String | Yes | Name of the data source |
| Description | String | No | Description of the data source |
| DataSourceConfiguration | DataSourceConfiguration | Yes | Configuration for the data source |
| VectorIngestionConfiguration | VectorIngestionConfiguration | No | Vector ingestion configuration |
DataSourceConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Type | String | Yes | Type of data source (S3, WEB, CUSTOM) |
| S3Configuration | S3Configuration | Cond | S3 configuration |
| WebConfiguration | WebConfiguration | Cond | Web crawl configuration |
S3Configuration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| BucketArn | String | Yes | ARN of the S3 bucket |
| InclusionPrefixes | List of String | No | Prefixes to include |
| ExclusionPrefixes | List of String | No | Prefixes to exclude |
WebConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| SourceUrl | String | Yes | URL to crawl |
| CrawlScope | String | No | Crawl scope (HOST_ONLY, SUBDOMAINS) |
| InclusionFilters | List of String | No | URL patterns to include |
| ExclusionFilters | List of String | No | URL patterns to exclude |
| ExtractionEngine | String | No | Extraction engine (NONE, CHANGE0, BEDROCK_FAST_CHUNKER) |
VectorIngestionConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| ChunkingConfiguration | ChunkingConfiguration | Yes | Chunking configuration |
ChunkingConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| ChunkingStrategy | String | Yes | Strategy (FIXED_SIZE, NONE, HIERARCHICAL) |
| FixedSizeChunking | FixedSizeChunking | Cond | Fixed size configuration |
| HierarchicalChunking | HierarchicalChunking | Cond | Hierarchical configuration |
FixedSizeChunking Structure
| Property | Type | Required | Description |
|---|---|---|---|
| MaxTokens | Integer | Yes | Maximum tokens per chunk |
| OverlapPercentage | Integer | No | Overlap percentage (0-25) |
HierarchicalChunking Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Level1MaxTokens | Integer | Yes | Max tokens for level 1 |
| Level2MaxTokens | Integer | Yes | Max tokens for level 2 |
| OverlapTokens | Integer | No | Overlap tokens |
Example
Resources:
MyDataSource:
Type: AWS::Bedrock::DataSource
Properties:
KnowledgeBaseId: !Ref KnowledgeBase
DataSourceName: !Sub "${AWS::StackName}-datasource"
Description: S3 data source for documents
DataSourceConfiguration:
Type: S3
S3Configuration:
BucketArn: !Ref DocumentBucket
InclusionPrefixes:
- documents/
- pdfs/
VectorIngestionConfiguration:
ChunkingConfiguration:
ChunkingStrategy: FIXED_SIZE
FixedSizeChunking:
MaxTokens: 512
OverlapPercentage: 20Attributes
| Attribute | Description |
|---|---|
| DataSourceId | The ID of the data source |
AWS::Bedrock::Guardrail
Creates a guardrail for content moderation.
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| GuardrailName | String | Yes | Name of the guardrail |
| Description | String | No | Description of the guardrail |
| TopicPolicy | TopicPolicy | No | Topic policy configuration |
| ContentPolicy | ContentPolicy | No | Content policy configuration |
| WordPolicy | WordPolicy | No | Word policy configuration |
| SensitiveInformationPolicy | SensitiveInformationPolicy | No | Sensitive info policy |
TopicPolicy Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Topics | List of Topic | Yes | List of topics |
Topic Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Name | String | Yes | Name of the topic |
| Definition | String | Yes | Definition of the topic |
| Examples | List of String | No | Examples of the topic |
| Type | String | Yes | Type (DENIED) |
ContentPolicy Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Filters | List of ContentFilter | Yes | Content filters |
ContentFilter Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Type | String | Yes | Filter type (PROFANITY, HATE, SEXUAL, VIOLENCE) |
| InputStrength | String | No | Input strength (NONE, LOW, MEDIUM, HIGH) |
| OutputStrength | String | No | Output strength (NONE, LOW, MEDIUM, HIGH) |
WordPolicy Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Words | List of Word | No | Custom words |
| ManagedWordLists | List of ManagedWordList | No | Managed word lists |
Word Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Text | String | Yes | Word text |
| InputAction | String | No | Input action (BLOCK, MASK) |
| OutputAction | String | No | Output action (BLOCK, MASK) |
ManagedWordList Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Type | String | Yes | Type (PROFANITY) |
SensitiveInformationPolicy Structure
| Property | Type | Required | Description |
|---|---|---|---|
| PiiEntities | List of PiiEntity | No | PII entities |
| Regexes | List of Regex | No | Custom regex patterns |
PiiEntity Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Name | String | Yes | PII type name |
| Action | String | Yes | Action (BLOCK, MASK) |
Regex Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Name | String | Yes | Regex name |
| Pattern | String | Yes | Regex pattern |
| Action | String | Yes | Action (BLOCK, MASK) |
ContextualGroundingPolicy Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Filters | List of GroundingFilter | Yes | Grounding filters |
GroundingFilter Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Type | String | Yes | Filter type (GROUNDING, RELEVANCE) |
| Threshold | Double | Yes | Threshold value (0-1) |
Example
Resources:
MyGuardrail:
Type: AWS::Bedrock::Guardrail
Properties:
GuardrailName: !Sub "${AWS::StackName}-guardrail"
Description: Content moderation guardrail
TopicPolicy:
Topics:
- Name: FinancialAdvice
Definition: Personalized financial investment advice
Type: DENIED
ContentPolicy:
Filters:
- Type: PROFANITY
InputStrength: LOW
OutputStrength: LOW
- Type: HATE
InputStrength: MEDIUM
OutputStrength: HIGH
WordPolicy:
Words:
- Text: "spam"
Action: BLOCK
ManagedWordLists:
- Type: PROFANITY
SensitiveInformationPolicy:
PiiEntities:
- Name: EMAIL
Action: MASK
- Name: SSN
Action: BLOCKAttributes
| Attribute | Description |
|---|---|
| GuardrailId | The ID of the guardrail |
| GuardrailVersion | The version of the guardrail |
| GuardrailArn | The ARN of the guardrail |
AWS::Bedrock::GuardrailVersion
Creates a version of a guardrail.
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| GuardrailId | String | Yes | ID of the guardrail |
| Description | String | No | Description of the version |
Attributes
| Attribute | Description |
|---|---|
| GuardrailVersion | The version of the guardrail |
AWS::Bedrock::Prompt
Creates a prompt template for reuse.
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| Name | String | Yes | Name of the prompt |
| Description | String | No | Description of the prompt |
| DefaultVariant | String | No | Default variant name |
| Variants | List of PromptVariant | Yes | Prompt variants |
PromptVariant Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Name | String | Yes | Variant name |
| Description | String | No | Variant description |
| Text | String | Yes | Prompt text |
| InferenceConfiguration | InferenceConfiguration | No | Model configuration |
InferenceConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Temperature | Double | No | Temperature (0-1) |
| TopP | Double | No | Top P (0-1) |
| MaxTokens | Integer | No | Max tokens |
| StopSequences | List of String | No | Stop sequences |
Example
Resources:
MyPrompt:
Type: AWS::Bedrock::Prompt
Properties:
Name: !Sub "${AWS::StackName}-support-prompt"
Description: Customer support prompt
DefaultVariant: empathetic
Variants:
- Name: empathetic
Description: Empathetic response style
Text: |
You are a helpful customer support agent.
Always be empathetic and understanding.
User query: {{query}}
InferenceConfiguration:
Temperature: 0.7
MaxTokens: 1000
- Name: professional
Description: Professional response style
Text: |
You are a professional customer support agent.
Provide factual and concise responses.
User query: {{query}}
InferenceConfiguration:
Temperature: 0.3
MaxTokens: 800Attributes
| Attribute | Description |
|---|---|
| Id | The ID of the prompt |
| Arn | The ARN of the prompt |
AWS::Bedrock::Flow
Creates a flow for workflow orchestration.
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| Name | String | Yes | Name of the flow |
| Description | String | No | Description of the flow |
| ExecutionRoleArn | String | Yes | ARN of the execution role |
| Definition | FlowDefinition | Yes | Flow definition |
| DefinitionS3Location | S3Location | No | S3 location of definition |
FlowDefinition Structure
| Property | Type | Required | Description |
|---|---|---|---|
| StartAt | String | Yes | Name of the starting node |
| Nodes | Map of FlowNode | Yes | Map of nodes |
| Connections | List of Connection | No | Connections between nodes |
FlowNode Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Type | String | Yes | Node type |
| Name | String | Yes | Node name |
| Description | String | No | Node description |
| Configuration | FlowNodeConfiguration | No | Node configuration |
| Transitions | Transitions | No | Node transitions |
| IsEnd | Boolean | No | Whether this is an end node |
FlowNodeConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| BedrockClassifierConfiguration | ClassifierConfiguration | Cond | Classifier config |
| BedrockModelConfiguration | ModelConfiguration | Cond | Model config |
| KnowledgeBaseConfiguration | FlowKnowledgeBaseConfiguration | Cond | Knowledge base config |
| LambdaConfiguration | LambdaConfiguration | Cond | Lambda config |
ClassifierConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| BedrockClassifierConfiguration | BedrockClassifierConfiguration | Yes | Bedrock classifier config |
BedrockClassifierConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| BedrockFoundationModelConfiguration | BedrockFoundationModelConfiguration | Yes | Model config |
| InputConfiguration | ClassifierInputConfiguration | Yes | Input config |
| OutputConfiguration | ClassifierOutputConfiguration | Yes | Output config |
ModelConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| ModelId | String | Yes | Model ID |
| InferenceConfiguration | InferenceConfiguration | No | Inference config |
Transitions Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Next | String | No | Next node name |
| Conditional | List of ConditionalTransition | No | Conditional transitions |
ConditionalTransition Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Next | String | Yes | Next node name |
| Condition | String | Yes | Condition expression |
Connection Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Name | String | Yes | Connection name |
| Source | String | Yes | Source node name |
| Target | String | Yes | Target node name |
| Type | String | Yes | Connection type |
Example
Resources:
MyFlow:
Type: AWS::Bedrock::Flow
Properties:
Name: !Sub "${AWS::StackName}-processing-flow"
Description: Customer request processing flow
ExecutionRoleArn: !GetAtt FlowRole.Arn
Definition:
StartAt: Classifier
Nodes:
Classifier:
Type: Classifier
Name: Classifier
Configuration:
BedrockClassifierConfiguration:
BedrockFoundationModelConfiguration:
ModelId: anthropic.claude-v3:5
InputConfiguration:
TextInput:
Name: input
OutputConfiguration:
StructuredOutput:
Name: intent
Transitions:
Next:
Support: intent.support
Sales: intent.sales
General: "*"
Support:
Type: KnowledgeBase
Name: SupportKnowledgeBase
Configuration:
KnowledgeBaseConfiguration:
KnowledgeBaseId: !Ref SupportKB
Transitions:
Next: ResponseGenerator
Sales:
Type: Model
Name: SalesModel
Configuration:
BedrockModelConfiguration:
ModelId: anthropic.claude-v3:5
Transitions:
Next: ResponseGenerator
General:
Type: Model
Name: GeneralModel
Configuration:
BedrockModelConfiguration:
ModelId: anthropic.claude-v3:5
Transitions:
Next: ResponseGenerator
ResponseGenerator:
Type: Model
Name: ResponseGenerator
Configuration:
BedrockModelConfiguration:
ModelId: anthropic.claude-v3:5
IsEnd: trueAttributes
| Attribute | Description |
|---|---|
| Id | The ID of the flow |
| Arn | The ARN of the flow |
| Status | The status of the flow |
AWS::Bedrock::ApplicationInferenceProfile
Creates an application inference profile for optimized model access.
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| ApplicationInferenceProfileName | String | Yes | Name of the profile |
| Description | String | No | Description of the profile |
| ModelSource | ModelSource | Yes | Source model configuration |
| InferenceConfiguration | InferenceConfiguration | No | Inference configuration |
ModelSource Structure
| Property | Type | Required | Description |
|---|---|---|---|
| CopyFrom | String | Yes | ARN to copy from |
InferenceConfiguration Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Text | Map of TextConfig | No | Text model configurations |
TextConfig Structure
| Property | Type | Required | Description |
|---|---|---|---|
| Temperature | Double | No | Temperature (0-1) |
| MaxTokens | Integer | No | Max tokens |
| TopP | Double | No | Top P (0-1) |
Example
Resources:
MyProfile:
Type: AWS::Bedrock::ApplicationInferenceProfile
Properties:
ApplicationInferenceProfileName: !Sub "${AWS::StackName}-profile"
Description: Production inference profile
ModelSource:
CopyFrom: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:application-inference-profile/*"
InferenceConfiguration:
Text:
anthropic.claude-v3:5:
Temperature: 0.7
MaxTokens: 4096
anthropic.claude-sonnet-4-20250514:
Temperature: 0.7
MaxTokens: 4096Attributes
| Attribute | Description |
|---|---|
| Id | The ID of the inference profile |
| Arn | The ARN of the inference profile |
Intrinsic Functions Reference
!Ref
Returns the value of the specified parameter or resource.
# Reference a parameter
AgentName: !Ref AgentNameParam
# Reference a resource (returns the physical ID)
AgentId: !Ref MyAgent!GetAtt
Returns the value of an attribute from a Bedrock resource.
# Get the agent ID
AgentId: !GetAtt MyAgent.AgentId
# Get the agent ARN
AgentArn: !GetAtt MyAgent.AgentArn
# Get knowledge base ID
KnowledgeBaseId: !GetAtt KnowledgeBase.KnowledgeBaseId
# Get guardrail ID
GuardrailId: !GetAtt Guardrail.GuardrailId!Sub
Substitutes variables in an input string.
# With variable substitution
AgentName: !Sub "${AWS::StackName}-agent"
# With multiple variables
ModelArn: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/${ModelId}"!ImportValue
Imports values exported by other stacks.
# Import from another stack
AgentId: !ImportValue
Fn::Sub: "${BedrockStackName}-AgentId"!FindInMap
Returns the value from a mapping.
# Find in mapping
Temperature: !FindInMap [ModelConfig, !Ref Model, Temperature]!If
Returns one value if condition is true, another if false.
# Conditional model selection
ModelId: !If [UseClaude, anthropic.claude-v3:5, amazon.titan-text-express-v1]IAM Policy Examples for Bedrock
Bedrock Agent Invoke Policy
Policies:
- PolicyName: BedrockAgentInvoke
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- bedrock:InvokeAgent
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:agent/*"Bedrock Model Invoke Policy
Policies:
- PolicyName: BedrockModelInvoke
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- bedrock:InvokeModel
- bedrock:InvokeModelWithResponseStream
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/*"Knowledge Base Access Policy
Policies:
- PolicyName: KnowledgeBaseAccess
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- bedrock:Retrieve
- bedrock:RetrieveAndGenerate
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:knowledge-base/*"Guardrail Policy
Policies:
- PolicyName: GuardrailPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- bedrock:ApplyGuardrail
Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:guardrail/*"Supported Foundation Models
| Model Provider | Model ID | Description |
|---|---|---|
| Anthropic | anthropic.claude-v2:1 | Claude 2.1 |
| Anthropic | anthropic.claude-v3:5 | Claude 3.5 Sonnet |
| Anthropic | anthropic.claude-sonnet-4-20250514 | Claude Sonnet 4 |
| Anthropic | anthropic.claude-haiku-3-20250514 | Claude Haiku 3 |
| Amazon | amazon.titan-text-express-v1 | Titan Text Express |
| Amazon | amazon.titan-text-lite-v1 | Titan Text Lite |
| Amazon | amazon.titan-embed-text-v1 | Titan Embeddings |
| Amazon | amazon.titan-embed-text-v2:0 | Titan Embeddings v2 |
| Meta | meta.llama3-70b-instruct-v1:0 | Llama 3 70B |
| Meta | meta.llama3-8b-instruct-v1:0 | Llama 3 8B |
| Meta | meta.llama3.1-70b-instruct-v1:0 | Llama 3.1 70B |
| Cohere | cohere.command-text-v14:0 | Command |
| Cohere | cohere.embed-multilingual-v3:0 | Multilingual Embeddings |
| Stability AI | stability.stable-diffusion-xl-v1 | Stable Diffusion XL |
Limits and Quotas
Bedrock Agent Limits
| Resource | Default Limit |
|---|---|
| Agents per account | 50 |
| Aliases per agent | 20 |
| Action groups per agent | 20 |
| Knowledge bases per agent | 10 |
| Agent session duration | 30 minutes |
Knowledge Base Limits
| Resource | Default Limit |
|---|---|
| Knowledge bases per account | 100 |
| Data sources per knowledge base | 10 |
| Documents per data source | 10,000,000 |
| Vector dimensions (Titan) | 1536 |
| Chunk size (max tokens) | 3000 |
Guardrail Limits
| Resource | Default Limit |
|---|---|
| Guardrails per account | 20 |
| Topics per guardrail | 10 |
| Words per guardrail | 1000 |
| PII types per guardrail | 50 |
| Regex patterns per guardrail | 10 |
Flow Limits
| Resource | Default Limit |
|---|---|
| Flows per account | 100 |
| Nodes per flow | 50 |
| Connections per flow | 100 |
| Flow execution duration | 30 minutes |
Common Tags for Bedrock
Resources:
MyAgent:
Type: AWS::Bedrock::Agent
Properties:
Tags:
- Key: Environment
Value: !Ref Environment
- Key: Project
Value: !Ref ProjectName
- Key: Owner
Value: team@example.com
- Key: ManagedBy
Value: CloudFormation
- Key: Version
Value: "1.0.0"