@@ -546,6 +546,44 @@ describe('VectorKnowledgeBase', () => {
546546 } ) . toThrow ( / S 3 v e c t o r i n d e x d i m e n s i o n \( 1 0 2 4 \) m u s t m a t c h t h e e m b e d d i n g s m o d e l d i m e n s i o n \( 1 5 3 6 \) / ) ;
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