aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 2.19 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.ReplicaProvider=void 0;var path=()=>{var tmp=require("path");return path=()=>tmp,tmp},iam=()=>{var tmp=require("../../aws-iam");return iam=()=>tmp,tmp},lambda=()=>{var tmp=require("../../aws-lambda");return lambda=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},cr=()=>{var tmp=require("../../custom-resources");return cr=()=>tmp,tmp};class ReplicaProvider extends core_1().NestedStack{static getOrCreate(scope,props){const stack=core_1().Stack.of(scope),uid="@aws-cdk/aws-dynamodb.ReplicaProvider";return stack.node.tryFindChild(uid)??new ReplicaProvider(stack,uid,props)}constructor(scope,id,props){super(scope,id);const code=lambda().Code.fromAsset(path().join(__dirname,"..","..","custom-resource-handlers","dist","aws-dynamodb","replica-handler"));this.onEventHandler=new(lambda()).Function(this,"OnEventHandler",{code,runtime:lambda().Runtime.NODEJS_18_X,handler:"index.onEventHandler",timeout:core_1().Duration.minutes(5)}),this.isCompleteHandler=new(lambda()).Function(this,"IsCompleteHandler",{code,runtime:lambda().Runtime.NODEJS_18_X,handler:"index.isCompleteHandler",timeout:core_1().Duration.seconds(30)}),this.onEventHandler.addToRolePolicy(new(iam()).PolicyStatement({actions:["iam:CreateServiceLinkedRole"],resources:[core_1().Stack.of(this).formatArn({service:"iam",region:"",resource:"role",resourceName:"aws-service-role/replication.dynamodb.amazonaws.com/AWSServiceRoleForDynamoDBReplication"})]})),this.onEventHandler.addToRolePolicy(new(iam()).PolicyStatement({actions:["dynamodb:DescribeLimits"],resources:["*"]}));let resources=[];props.regions.forEach(region=>{resources.push(`arn:${core_1().Aws.PARTITION}:dynamodb:${region}:${this.account}:table/${props.tableName}`)}),this.onEventHandler.addToRolePolicy(new(iam()).PolicyStatement({actions:["dynamodb:DeleteTable","dynamodb:DeleteTableReplica"],resources})),this.provider=new(cr()).Provider(this,"Provider",{onEventHandler:this.onEventHandler,isCompleteHandler:this.isCompleteHandler,queryInterval:core_1().Duration.seconds(10),totalTimeout:props.timeout})}}exports.ReplicaProvider=ReplicaProvider;