Skip to content

Commit 6620867

Browse files
committed
Create a customer-managed KMS key and grant Bedrock permission to decrypt
1 parent 156648a commit 6620867

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

packages/cdk/stacks/EpsAssistMeStack.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
Stack,
44
StackProps,
55
RemovalPolicy,
6-
Fn,
76
CfnOutput
87
} from "aws-cdk-lib"
98
import {
@@ -108,10 +107,17 @@ export class EpsAssistMeStack extends Stack {
108107
objectOwnership: ObjectOwnership.BUCKET_OWNER_ENFORCED
109108
})
110109

111-
// Define the S3 bucket for knowledge base documents
110+
// Create a customer-managed KMS key
111+
const kbDocsKey = new Key(this, "KbDocsKey", {
112+
enableKeyRotation: true,
113+
description: "KMS key for encrypting knowledge base documents"
114+
})
115+
116+
// Use the KMS key in your S3 bucket
112117
const kbDocsBucket = new Bucket(this, "EpsAssistDocsBucket", {
113118
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
114119
encryption: BucketEncryption.KMS,
120+
encryptionKey: kbDocsKey,
115121
removalPolicy: RemovalPolicy.DESTROY,
116122
autoDeleteObjects: true,
117123
enforceSSL: true,
@@ -168,7 +174,15 @@ export class EpsAssistMeStack extends Stack {
168174
bedrockExecutionRole.addToPolicy(s3AccessGetPolicy)
169175
bedrockExecutionRole.addToPolicy(bedrockKBDeleteRolePolicy)
170176

171-
// ==== Bedrock Guardrail and Version ====
177+
// Grant Bedrock permission to decrypt
178+
kbDocsKey.addToResourcePolicy(new iam.PolicyStatement({
179+
effect: iam.Effect.ALLOW,
180+
principals: [new iam.ArnPrincipal(bedrockExecutionRole.roleArn)],
181+
actions: ["kms:Decrypt", "kms:DescribeKey"],
182+
resources: ["*"]
183+
}))
184+
185+
// Create bedrock Guardrails for the slack bot
172186
const guardrail = new CfnGuardrail(this, "EpsGuardrail", {
173187
name: "eps-assist-guardrail",
174188
description: "Guardrail for EPS Assist Me bot",
@@ -197,6 +211,7 @@ export class EpsAssistMeStack extends Stack {
197211
}
198212
})
199213

214+
// Add a dependency for the guardrail to the bedrock execution role
200215
const guardrailVersion = new CfnGuardrailVersion(this, "EpsGuardrailVersion", {
201216
guardrailIdentifier: guardrail.attrGuardrailId,
202217
description: "v1.0"

0 commit comments

Comments
 (0)