aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 4.93 kB
JavaScript
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Provider=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var path=()=>{var tmp=require("path");return path=()=>tmp,tmp},constructs_1=()=>{var tmp=require("constructs");return constructs_1=()=>tmp,tmp},consts=()=>{var tmp=require("./runtime/consts");return consts=()=>tmp,tmp},util_1=()=>{var tmp=require("./util");return util_1=()=>tmp,tmp},waiter_state_machine_1=()=>{var tmp=require("./waiter-state-machine");return waiter_state_machine_1=()=>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};const 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||props.waiterStateMachineLogOptions||props.disableWaiterStateMachineLogging!==void 0))throw new Error('"queryInterval", "totalTimeout", "waiterStateMachineLogOptions", and "disableWaiterStateMachineLogging" can only be configured if "isCompleteHandler" is specified. Otherwise, they have no meaning');if(props.role&&(props.frameworkOnEventRole||props.frameworkCompleteAndTimeoutRole))throw new(core_1()).ValidationError('Cannot specify both "role" and any of "frameworkOnEventRole" or "frameworkCompleteAndTimeoutRole".',this);if(!props.isCompleteHandler&&props.frameworkCompleteAndTimeoutRole)throw new(core_1()).ValidationError('Cannot specify "frameworkCompleteAndTimeoutRole" when "isCompleteHandler" is not specified.',this);this.onEventHandler=props.onEventHandler,this.isCompleteHandler=props.isCompleteHandler,this.logRetention=props.logRetention,this.logGroup=props.logGroup,this.vpc=props.vpc,this.vpcSubnets=props.vpcSubnets,this.securityGroups=props.securityGroups,this.role=props.role,this.providerFunctionEnvEncryption=props.providerFunctionEnvEncryption;const onEventFunction=this.createFunction(consts().FRAMEWORK_ON_EVENT_HANDLER_NAME,props.providerFunctionName,props.frameworkOnEventRole);if(this.isCompleteHandler){const isCompleteFunction=this.createFunction(consts().FRAMEWORK_IS_COMPLETE_HANDLER_NAME,void 0,props.frameworkCompleteAndTimeoutRole),timeoutFunction=this.createFunction(consts().FRAMEWORK_ON_TIMEOUT_HANDLER_NAME,void 0,props.frameworkCompleteAndTimeoutRole),retry=(0,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,logOptions:props.waiterStateMachineLogOptions,disableLogging:props.disableWaiterStateMachineLogging});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}}addPermissions(frameworkLambda,userDefinedHandlerLambda){userDefinedHandlerLambda.grantInvoke(frameworkLambda),frameworkLambda.addToRolePolicy(new(iam()).PolicyStatement({effect:iam().Effect.ALLOW,actions:["lambda:GetFunction"],resources:[userDefinedHandlerLambda.functionArn]}))}createFunction(entrypoint,name,role){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().determineLatestNodeRuntime(this),handler:`framework.${entrypoint}`,timeout:FRAMEWORK_HANDLER_TIMEOUT,...this.logRetention?{logRetention:this.logRetention}:{},logGroup:this.logGroup,vpc:this.vpc,vpcSubnets:this.vpcSubnets,securityGroups:this.securityGroups,role:this.role??role,functionName:name,environmentEncryption:this.providerFunctionEnvEncryption});return fn.addEnvironment(consts().USER_ON_EVENT_FUNCTION_ARN_ENV,this.onEventHandler.functionArn),this.addPermissions(fn,this.onEventHandler),this.isCompleteHandler&&(fn.addEnvironment(consts().USER_IS_COMPLETE_FUNCTION_ARN_ENV,this.isCompleteHandler.functionArn),this.addPermissions(fn,this.isCompleteHandler)),fn}}exports.Provider=Provider,_a=JSII_RTTI_SYMBOL_1,Provider[_a]={fqn:"aws-cdk-lib.custom_resources.Provider",version:"2.185.0"};