55 VectorCollection ,
66 VectorCollectionStandbyReplicas
77} from "@cdklabs/generative-ai-cdk-constructs/lib/cdk-lib/opensearchserverless"
8+ import { generatePhysicalNameV2 } from "@cdklabs/generative-ai-cdk-constructs/lib/common/helpers/utils"
9+ import { CfnAccessPolicy } from "aws-cdk-lib/aws-opensearchserverless"
810
911export interface OpenSearchResourcesProps {
1012 readonly stackName : string
@@ -15,6 +17,7 @@ export interface OpenSearchResourcesProps {
1517
1618export class OpenSearchResources extends Construct {
1719 public readonly collection : VectorCollection
20+ public readonly deploymentPolicy : CfnAccessPolicy
1821
1922 constructor ( scope : Construct , id : string , props : OpenSearchResourcesProps ) {
2023 super ( scope , id )
@@ -31,7 +34,34 @@ export class OpenSearchResources extends Construct {
3134
3235 // Grant access to the Bedrock execution role
3336 this . collection . grantDataAccess ( props . bedrockExecutionRole )
34- this . collection . grantDataAccess ( props . cdkExecutionRole )
37+
38+ // Grant access to the CDK execution role for deployment operations
39+ const dataAccessPolicyName = generatePhysicalNameV2 ( this ,
40+ "DataAccessPolicy" ,
41+ { maxLength : 32 , lower : true } )
42+ const dataAccessPolicyDocument = [ {
43+ Rules : [
44+ {
45+ Resource : [ `index/${ this . collection . collectionName } /*` ] ,
46+ Permission : [
47+ "aoss:UpdateIndex" ,
48+ "aoss:DescribeIndex" ,
49+ "aoss:CreateIndex" ,
50+ "aoss:DeleteIndex"
51+ ] ,
52+ ResourceType : "index"
53+ }
54+ ] ,
55+ Principal : [
56+ props . cdkExecutionRole . roleArn
57+ ] ,
58+ Description : ""
59+ } ]
60+ this . deploymentPolicy = new CfnAccessPolicy ( this , "DataAccessPolicy" , {
61+ name : dataAccessPolicyName ,
62+ type : "data" ,
63+ policy : JSON . stringify ( dataAccessPolicyDocument )
64+ } )
3565
3666 }
3767}
0 commit comments