aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 3.13 kB
JavaScript
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Provider=void 0;const jsiiDeprecationWarnings=require("../../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),path=require("path"),lambda=require("../../../aws-lambda"),core_1=require("../../../core"),constructs_1=require("constructs"),consts=require("./runtime/consts"),util_1=require("./util"),waiter_state_machine_1=require("./waiter-state-machine"),RUNTIME_HANDLER_PATH=path.join(__dirname,"runtime"),FRAMEWORK_HANDLER_TIMEOUT=core_1.Duration.minutes(15);class Provider extends constructs_1.Construct{constructor(scope,id,props){super(scope,id);try{jsiiDeprecationWarnings.aws_cdk_lib_custom_resources_ProviderProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,Provider),error}if(!props.isCompleteHandler&&(props.queryInterval||props.totalTimeout))throw new Error('"queryInterval" and "totalTimeout" can only be configured if "isCompleteHandler" is specified. Otherwise, they have no meaning');this.onEventHandler=props.onEventHandler,this.isCompleteHandler=props.isCompleteHandler,this.logRetention=props.logRetention,this.vpc=props.vpc,this.vpcSubnets=props.vpcSubnets,this.securityGroups=props.securityGroups,this.role=props.role;const onEventFunction=this.createFunction(consts.FRAMEWORK_ON_EVENT_HANDLER_NAME,props.providerFunctionName);if(this.isCompleteHandler){const isCompleteFunction=this.createFunction(consts.FRAMEWORK_IS_COMPLETE_HANDLER_NAME),timeoutFunction=this.createFunction(consts.FRAMEWORK_ON_TIMEOUT_HANDLER_NAME),retry=util_1.calculateRetryPolicy(props),waiterStateMachine=new waiter_state_machine_1.WaiterStateMachine(this,"waiter-state-machine",{isCompleteHandler:isCompleteFunction,timeoutHandler:timeoutFunction,backoffRate:retry.backoffRate,interval:retry.interval,maxAttempts:retry.maxAttempts});onEventFunction.addEnvironment(consts.WAITER_STATE_MACHINE_ARN_ENV,waiterStateMachine.stateMachineArn),waiterStateMachine.grantStartExecution(onEventFunction)}this.entrypoint=onEventFunction,this.serviceToken=this.entrypoint.functionArn}bind(_scope){return{serviceToken:this.entrypoint.functionArn}}createFunction(entrypoint,name){const fn=new lambda.Function(this,`framework-${entrypoint}`,{code:lambda.Code.fromAsset(RUNTIME_HANDLER_PATH,{exclude:["*.ts"]}),description:`AWS CDK resource provider framework - ${entrypoint} (${this.node.path})`.slice(0,256),runtime:lambda.Runtime.NODEJS_14_X,handler:`framework.${entrypoint}`,timeout:FRAMEWORK_HANDLER_TIMEOUT,logRetention:this.logRetention,vpc:this.vpc,vpcSubnets:this.vpcSubnets,securityGroups:this.securityGroups,role:this.role,functionName:name});return fn.addEnvironment(consts.USER_ON_EVENT_FUNCTION_ARN_ENV,this.onEventHandler.functionArn),this.onEventHandler.grantInvoke(fn),this.isCompleteHandler&&(fn.addEnvironment(consts.USER_IS_COMPLETE_FUNCTION_ARN_ENV,this.isCompleteHandler.functionArn),this.isCompleteHandler.grantInvoke(fn)),fn}}exports.Provider=Provider,_a=JSII_RTTI_SYMBOL_1,Provider[_a]={fqn:"aws-cdk-lib.custom_resources.Provider",version:"2.70.0"};