$npx -y skills add giuseppe-trisciuoglio/developer-kit --skill aws-cloudformation-bedrockProvides 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 st
| 1 | # AWS CloudFormation Amazon Bedrock |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | 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. |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | - Creating Bedrock agents with action groups |
| 10 | - Implementing RAG with knowledge bases |
| 11 | - Configuring S3 or web crawl data sources |
| 12 | - Setting up content moderation guardrails |
| 13 | - Managing prompt templates |
| 14 | - Orchestrating AI workflows with Bedrock Flows |
| 15 | - Configuring inference profiles for multi-model access |
| 16 | - Organizing templates with Parameters and cross-stack references |
| 17 | |
| 18 | ## Instructions |
| 19 | |
| 20 | ### 1. Define Parameters |
| 21 | |
| 22 | ```yaml |
| 23 | Parameters: |
| 24 | FoundationModel: |
| 25 | Type: String |
| 26 | Default: anthropic.claude-3-sonnet-20240229-v1:0 |
| 27 | AllowedValues: |
| 28 | - anthropic.claude-3-sonnet-20240229-v1:0 |
| 29 | - anthropic.claude-3-haiku-20240307-v1:0 |
| 30 | - amazon.titan-text-express-v1 |
| 31 | Description: Foundation model for agent |
| 32 | ``` |
| 33 | |
| 34 | ### 2. Create Agent Role |
| 35 | |
| 36 | ```yaml |
| 37 | Resources: |
| 38 | AgentRole: |
| 39 | Type: AWS::IAM::Role |
| 40 | Properties: |
| 41 | AssumeRolePolicyDocument: |
| 42 | Version: "2012-10-17" |
| 43 | Statement: |
| 44 | - Effect: Allow |
| 45 | Principal: |
| 46 | Service: bedrock.amazonaws.com |
| 47 | Action: sts:AssumeRole |
| 48 | Policies: |
| 49 | - PolicyName: BedrockPermissions |
| 50 | PolicyDocument: |
| 51 | Version: "2012-10-17" |
| 52 | Statement: |
| 53 | - Effect: Allow |
| 54 | Action: |
| 55 | - bedrock:InvokeModel |
| 56 | Resource: !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:foundation-model/${FoundationModel}" |
| 57 | ``` |
| 58 | |
| 59 | ### 3. Create Agent |
| 60 | |
| 61 | ```yaml |
| 62 | BedrockAgent: |
| 63 | Type: AWS::Bedrock::Agent |
| 64 | Properties: |
| 65 | AgentName: !Sub "${AWS::StackName}-agent" |
| 66 | AgentResourceRoleArn: !GetAtt AgentRole.Arn |
| 67 | FoundationModelArn: !Sub "arn:aws:bedrock:${AWS::Region}::foundation-model/${FoundationModel}" |
| 68 | AutoPrepare: true |
| 69 | Instruction: | |
| 70 | You are a helpful assistant. Use the knowledge base to answer questions. |
| 71 | ``` |
| 72 | |
| 73 | ### 4. Create Knowledge Base |
| 74 | |
| 75 | ```yaml |
| 76 | KnowledgeBaseRole: |
| 77 | Type: AWS::IAM::Role |
| 78 | Properties: |
| 79 | AssumeRolePolicyDocument: |
| 80 | Version: "2012-10-17" |
| 81 | Statement: |
| 82 | - Effect: Allow |
| 83 | Principal: |
| 84 | Service: bedrock.amazonaws.com |
| 85 | Action: sts:AssumeRole |
| 86 | |
| 87 | KnowledgeBase: |
| 88 | Type: AWS::Bedrock::KnowledgeBase |
| 89 | Properties: |
| 90 | Name: !Sub "${AWS::StackName}-kb" |
| 91 | RoleArn: !GetAtt KnowledgeBaseRole.Arn |
| 92 | KnowledgeBaseConfiguration: |
| 93 | Type: VECTOR |
| 94 | VectorKnowledgeBaseConfiguration: |
| 95 | EmbeddingModelArn: !Sub "arn:aws:bedrock:${AWS::Region}::embedding-model/amazon.titan-embed-text-v1" |
| 96 | ``` |
| 97 | |
| 98 | ### 5. Create Data Source |
| 99 | |
| 100 | ```yaml |
| 101 | DataBucket: |
| 102 | Type: AWS::S3::Bucket |
| 103 | |
| 104 | S3DataSource: |
| 105 | Type: AWS::Bedrock::DataSource |
| 106 | Properties: |
| 107 | KnowledgeBaseId: !Ref KnowledgeBase |
| 108 | Name: s3-data-source |
| 109 | Type: S3 |
| 110 | DataSourceConfiguration: |
| 111 | S3Configuration: |
| 112 | BucketArn: !GetAtt DataBucket.Arn |
| 113 | InclusionPrefixes: |
| 114 | - documents/ |
| 115 | ``` |
| 116 | |
| 117 | ### 6. Add Guardrail |
| 118 | |
| 119 | ```yaml |
| 120 | Guardrail: |
| 121 | Type: AWS::Bedrock::Guardrail |
| 122 | Properties: |
| 123 | Name: !Sub "${AWS::StackName}-guardrail" |
| 124 | BlockedInputMessaging: "I cannot help with that request." |
| 125 | ContentPolicyConfig: |
| 126 | filtersConfig: |
| 127 | - type: PROFANITY |
| 128 | - type: MISCONDUCT |
| 129 | ``` |
| 130 | |
| 131 | ### 7. Create Action Group |
| 132 | |
| 133 | ```yaml |
| 134 | ActionLambdaFunction: |
| 135 | Type: AWS::Lambda::Function |
| 136 | Properties: |
| 137 | Runtime: python3.12 |
| 138 | Handler: index.handler |
| 139 | Role: !GetAtt ActionLambdaRole.Arn |
| 140 | Code: |
| 141 | ZipFile: | |
| 142 | def handler(event, context): |
| 143 | return {"statusCode": 200, "body": "{\"result\": \"success\"}"} |
| 144 | |
| 145 | ActionGroup: |
| 146 | Type: AWS::Bedrock::AgentActionGroup |
| 147 | Properties: |
| 148 | ActionGroupName: api-operations |
| 149 | ActionGroupState: ENABLED |
| 150 | AgentId: !GetAtt BedrockAgent.AgentId |
| 151 | ActionGroupExecutor: |
| 152 | Lambda: !Ref ActionLambdaFunction |
| 153 | FunctionSchema: |
| 154 | functionConfigurations: |
| 155 | - function: | |
| 156 | { "name": "get_inventory", "description": "Get current inventory status", "parameters": { "type": "object", "properties": { "sku": { "type": "string" } }, "required": [] } } |
| 157 | ``` |
| 158 | |
| 159 | ### 8. V |