Skip to content

Commit d3679da

Browse files
committed
Move Bedrock Execution Role for Knowledge Base in cdk stack
1 parent 09e1125 commit d3679da

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

packages/cdk/stacks/EpsAssistMeStack.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,41 @@ export class EpsAssistMeStack extends Stack {
134134
}])
135135
})
136136

137+
// ==== Bedrock Execution Role for Knowledge Base ====
138+
// This role allows Bedrock to access S3 documents, use OpenSearch Serverless, and call the embedding model.
139+
const bedrockKbRole = new Role(this, "EpsAssistMeBedrockExecutionRole", {
140+
assumedBy: new ServicePrincipal("bedrock.amazonaws.com"),
141+
description: "Role for Bedrock Knowledge Base to access S3 and OpenSearch"
142+
})
143+
144+
// Allow Bedrock to read/list objects in the docs S3 bucket
145+
bedrockKbRole.addToPolicy(new PolicyStatement({
146+
actions: ["s3:GetObject", "s3:ListBucket"],
147+
resources: [
148+
kbDocsBucket.bucketArn,
149+
`${kbDocsBucket.bucketArn}/*`
150+
]
151+
}))
152+
153+
// Allow Bedrock full access to your OpenSearch Serverless collection and its indexes
154+
// For production, consider narrowing to only what you need
155+
bedrockKbRole.addToPolicy(new PolicyStatement({
156+
actions: ["aoss:*"],
157+
resources: [
158+
osCollection.attrArn, // Collection itself
159+
`${osCollection.attrArn}/*`, // All child resources (indexes)
160+
"*" // For initial development, broad access
161+
]
162+
}))
163+
164+
// Allow Bedrock to call the embedding model
165+
bedrockKbRole.addToPolicy(new PolicyStatement({
166+
actions: ["bedrock:InvokeModel"],
167+
resources: [
168+
`arn:aws:bedrock:${region}::foundation-model/amazon.titan-embed-text-v2:0`
169+
]
170+
}))
171+
137172
// ==== Lambda Function for Vector Index Creation ====
138173
const createIndexFunction = new LambdaFunction(this, "CreateIndexFunction", {
139174
stackName: props.stackName,
@@ -219,41 +254,6 @@ export class EpsAssistMeStack extends Stack {
219254
])
220255
})
221256

222-
// ==== Bedrock Execution Role for Knowledge Base ====
223-
// This role allows Bedrock to access S3 documents, use OpenSearch Serverless, and call the embedding model.
224-
const bedrockKbRole = new Role(this, "EpsAssistMeBedrockExecutionRole", {
225-
assumedBy: new ServicePrincipal("bedrock.amazonaws.com"),
226-
description: "Role for Bedrock Knowledge Base to access S3 and OpenSearch"
227-
})
228-
229-
// Allow Bedrock to read/list objects in the docs S3 bucket
230-
bedrockKbRole.addToPolicy(new PolicyStatement({
231-
actions: ["s3:GetObject", "s3:ListBucket"],
232-
resources: [
233-
kbDocsBucket.bucketArn,
234-
`${kbDocsBucket.bucketArn}/*`
235-
]
236-
}))
237-
238-
// Allow Bedrock full access to your OpenSearch Serverless collection and its indexes
239-
// For production, consider narrowing to only what you need
240-
bedrockKbRole.addToPolicy(new PolicyStatement({
241-
actions: ["aoss:*"],
242-
resources: [
243-
osCollection.attrArn, // Collection itself
244-
`${osCollection.attrArn}/*`, // All child resources (indexes)
245-
"*" // For initial development, broad access
246-
]
247-
}))
248-
249-
// Allow Bedrock to call the embedding model
250-
bedrockKbRole.addToPolicy(new PolicyStatement({
251-
actions: ["bedrock:InvokeModel"],
252-
resources: [
253-
`arn:aws:bedrock:${region}::foundation-model/amazon.titan-embed-text-v2:0`
254-
]
255-
}))
256-
257257
// ==== Bedrock Knowledge Base Resource ====
258258
// Reference the execution role created above
259259
const kb = new CfnKnowledgeBase(this, "EpsKb", {

0 commit comments

Comments
 (0)