aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 1.61 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.ReplicaProvider=void 0;const path=require("path"),iam=require("../../aws-iam"),lambda=require("../../aws-lambda"),core_1=require("../../core"),cr=require("../../custom-resources");class ReplicaProvider extends core_1.NestedStack{constructor(scope,id,props={}){super(scope,id);const code=lambda.Code.fromAsset(path.join(__dirname,"replica-handler"));this.onEventHandler=new lambda.Function(this,"OnEventHandler",{code,runtime:lambda.Runtime.NODEJS_14_X,handler:"index.onEventHandler",timeout:core_1.Duration.minutes(5)}),this.isCompleteHandler=new lambda.Function(this,"IsCompleteHandler",{code,runtime:lambda.Runtime.NODEJS_14_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:["*"]})),this.provider=new cr.Provider(this,"Provider",{onEventHandler:this.onEventHandler,isCompleteHandler:this.isCompleteHandler,queryInterval:core_1.Duration.seconds(10),totalTimeout:props.timeout})}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)}}exports.ReplicaProvider=ReplicaProvider;