Skip to content

Commit d0b73a6

Browse files
author
Gareth Oakley
committed
fix(bedrock): grant delete vectors permission to knowledge base execution role
fixes #1305
1 parent c9c16e6 commit d0b73a6

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/cdk-lib/bedrock/knowledge-bases/vector-knowledge-base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ export class VectorKnowledgeBase extends VectorKnowledgeBaseBase {
890890
// Grant the KB role read and write access to the vector index
891891
vectorStore.vectorBucket.grantRead(this.role, [vectorStore.vectorIndexName]);
892892
vectorStore.vectorBucket.grantWrite(this.role, [vectorStore.vectorIndexName]);
893+
vectorStore.vectorBucket.grantDelete(this.role, [vectorStore.vectorIndexName]);
893894
return {
894895
vectorStore: vectorStore,
895896
vectorStoreType: VectorStoreType.S3_VECTORS,

test/cdk-lib/bedrock/knowledge-base.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,44 @@ describe('VectorKnowledgeBase', () => {
546546
}).toThrow(/S3 vector index dimension \(1024\) must match the embeddings model dimension \(1536\)/);
547547
});
548548

549+
test('S3 VectorIndex Knowledge Base execution role should have DeleteVectors permission', () => {
550+
const s3App = new cdk.App();
551+
const s3Stack = new cdk.Stack(s3App, 'S3VectorsPermissionsTestStack', {
552+
env: { account: '123456789012', region: 'us-east-1' },
553+
});
554+
const model = BedrockFoundationModel.TITAN_EMBED_TEXT_V1;
555+
const vectorBucket = new VectorBucket(s3Stack, 'S3VectorBucket');
556+
const vectorIndex = new VectorIndex(s3Stack, 'S3VectorIndex', {
557+
vectorBucket,
558+
dimension: model.vectorDimensions!,
559+
});
560+
561+
new VectorKnowledgeBase(s3Stack, 'S3VectorsKnowledgeBase', {
562+
embeddingsModel: model,
563+
vectorStore: vectorIndex,
564+
});
565+
566+
const s3VectorsTemplate = Template.fromStack(s3Stack);
567+
568+
// Verify that the execution role has s3vectors:DeleteVectors permission
569+
s3VectorsTemplate.hasResourceProperties('AWS::IAM::Policy', {
570+
PolicyDocument: {
571+
Statement: Match.arrayWith([
572+
Match.objectLike({
573+
Action: Match.arrayWith(['s3vectors:DeleteVectors']),
574+
Effect: 'Allow',
575+
// Check the resource is scoped to a specific index
576+
Resource: Match.objectLike({
577+
'Fn::Join': Match.arrayWith([
578+
Match.arrayWith(['/index/']),
579+
]),
580+
}),
581+
}),
582+
]),
583+
},
584+
});
585+
});
586+
549587
test('Should correctly initialize with SupplementalDataStorageLocation', () => {
550588
const model = BedrockFoundationModel.TITAN_EMBED_TEXT_V1;
551589
const vectorStore = new VectorCollection(stack, 'VectorCollection4');

0 commit comments

Comments
 (0)