aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 10.8 kB
JavaScript
;var __esDecorate=exports&&exports.__esDecorate||function(ctor,descriptorIn,decorators,contextIn,initializers,extraInitializers){function accept(f){if(f!==void 0&&typeof f!="function")throw new TypeError("Function expected");return f}for(var kind=contextIn.kind,key=kind==="getter"?"get":kind==="setter"?"set":"value",target=!descriptorIn&&ctor?contextIn.static?ctor:ctor.prototype:null,descriptor=descriptorIn||(target?Object.getOwnPropertyDescriptor(target,contextIn.name):{}),_,done=!1,i=decorators.length-1;i>=0;i--){var context={};for(var p in contextIn)context[p]=p==="access"?{}:contextIn[p];for(var p in contextIn.access)context.access[p]=contextIn.access[p];context.addInitializer=function(f){if(done)throw new TypeError("Cannot add initializers after decoration has completed");extraInitializers.push(accept(f||null))};var result=(0,decorators[i])(kind==="accessor"?{get:descriptor.get,set:descriptor.set}:descriptor[key],context);if(kind==="accessor"){if(result===void 0)continue;if(result===null||typeof result!="object")throw new TypeError("Object expected");(_=accept(result.get))&&(descriptor.get=_),(_=accept(result.set))&&(descriptor.set=_),(_=accept(result.init))&&initializers.unshift(_)}else(_=accept(result))&&(kind==="field"?initializers.unshift(_):descriptor[key]=_)}target&&Object.defineProperty(target,contextIn.name,descriptor),done=!0},__runInitializers=exports&&exports.__runInitializers||function(thisArg,initializers,value){for(var useValue=arguments.length>2,i=0;i<initializers.length;i++)value=useValue?initializers[i].call(thisArg,value):initializers[i].call(thisArg);return useValue?value:void 0};Object.defineProperty(exports,"__esModule",{value:!0}),exports.AwsCustomResource=exports.AwsCustomResourcePolicy=exports.PhysicalResourceId=exports.PhysicalResourceIdReference=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var constructs_1=()=>{var tmp=require("constructs");return constructs_1=()=>tmp,tmp},logging_1=()=>{var tmp=require("./logging");return logging_1=()=>tmp,tmp},iam=()=>{var tmp=require("../../../aws-iam");return iam=()=>tmp,tmp},cdk=()=>{var tmp=require("../../../core");return cdk=()=>tmp,tmp},core_1=()=>{var tmp=require("../../../core");return core_1=()=>tmp,tmp},prop_injectable_1=()=>{var tmp=require("../../../core/lib/prop-injectable");return prop_injectable_1=()=>tmp,tmp},aws_custom_resource_provider_generated_1=()=>{var tmp=require("../../../custom-resource-handlers/dist/custom-resources/aws-custom-resource-provider.generated");return aws_custom_resource_provider_generated_1=()=>tmp,tmp},cxapi=()=>{var tmp=require("../../../cx-api");return cxapi=()=>tmp,tmp},sdk_info_1=()=>{var tmp=require("../helpers-internal/sdk-info");return sdk_info_1=()=>tmp,tmp};const PHYSICAL_RESOURCE_ID_REFERENCE="PHYSICAL:RESOURCEID:";class PhysicalResourceIdReference{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.custom_resources.PhysicalResourceIdReference",version:"2.233.0"};creationStack=cdk().captureStackTrace();toJSON(){return PHYSICAL_RESOURCE_ID_REFERENCE}resolve(_context){try{jsiiDeprecationWarnings().aws_cdk_lib_IResolveContext(_context)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.resolve),error}return PHYSICAL_RESOURCE_ID_REFERENCE}toString(){return PHYSICAL_RESOURCE_ID_REFERENCE}}exports.PhysicalResourceIdReference=PhysicalResourceIdReference;class PhysicalResourceId{responsePath;id;static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.custom_resources.PhysicalResourceId",version:"2.233.0"};static fromResponse(responsePath){return new PhysicalResourceId(responsePath,void 0)}static of(id){return new PhysicalResourceId(void 0,id)}constructor(responsePath,id){this.responsePath=responsePath,this.id=id}}exports.PhysicalResourceId=PhysicalResourceId;class AwsCustomResourcePolicy{statements;resources;static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.custom_resources.AwsCustomResourcePolicy",version:"2.233.0"};static ANY_RESOURCE=["*"];static fromStatements(statements){return new AwsCustomResourcePolicy(statements,void 0)}static fromSdkCalls(options){try{jsiiDeprecationWarnings().aws_cdk_lib_custom_resources_SdkCallsPolicyOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromSdkCalls),error}return new AwsCustomResourcePolicy([],options.resources)}constructor(statements,resources){this.statements=statements,this.resources=resources}}exports.AwsCustomResourcePolicy=AwsCustomResourcePolicy;let AwsCustomResource=(()=>{let _classDecorators=[prop_injectable_1().propertyInjectable],_classDescriptor,_classExtraInitializers=[],_classThis,_classSuper=constructs_1().Construct;var AwsCustomResource2=class extends _classSuper{static{_classThis=this}static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;__esDecorate(null,_classDescriptor={value:_classThis},_classDecorators,{kind:"class",name:_classThis.name,metadata:_metadata},null,_classExtraInitializers),AwsCustomResource2=_classThis=_classDescriptor.value,_metadata&&Object.defineProperty(_classThis,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.custom_resources.AwsCustomResource",version:"2.233.0"};static PROPERTY_INJECTION_ID="aws-cdk-lib.aws-custom-resources.AwsCustomResource";static PROVIDER_FUNCTION_UUID="679f53fa-c002-430c-b0da-5b7982bd2287";static breakIgnoreErrorsCircuit(sdkCalls,caller){for(const call of sdkCalls)if(call?.ignoreErrorCodesMatching)throw new(cdk()).UnscopedValidationError(`\`${caller}\` cannot be called along with \`ignoreErrorCodesMatching\`.`)}grantPrincipal;customResource;props;constructor(scope,id,props){super(scope,id);try{jsiiDeprecationWarnings().aws_cdk_lib_custom_resources_AwsCustomResourceProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,AwsCustomResource2),error}if(!props.onCreate&&!props.onUpdate&&!props.onDelete)throw new(cdk()).ValidationError("At least `onCreate`, `onUpdate` or `onDelete` must be specified.",this);if(!props.role&&!props.policy)throw new(cdk()).ValidationError("At least one of `policy` or `role` (or both) must be specified.",this);if(props.onCreate&&!props.onCreate.physicalResourceId)throw new(cdk()).ValidationError("'physicalResourceId' must be specified for 'onCreate' call.",this);if(!props.onCreate&&props.onUpdate&&!props.onUpdate.physicalResourceId)throw new(cdk()).ValidationError("'physicalResourceId' must be specified for 'onUpdate' call when 'onCreate' is omitted.",this);for(const call of[props.onCreate,props.onUpdate,props.onDelete])call?.physicalResourceId?.responsePath&&AwsCustomResource2.breakIgnoreErrorsCircuit([call],"PhysicalResourceId.fromResponse");for(const call of[props.onCreate,props.onUpdate,props.onDelete])if(call?.externalId&&!call?.assumedRoleArn)throw new(cdk()).ValidationError("ExternalId can only be provided when assumedRoleArn is specified.",this);if(includesPhysicalResourceIdRef(props.onCreate?.parameters))throw new(cdk()).ValidationError("`PhysicalResourceIdReference` must not be specified in `onCreate` parameters.",this);this.props=props;let memorySize=props.memorySize;props.installLatestAwsSdk&&(memorySize??=512);const provider=new(aws_custom_resource_provider_generated_1()).AwsCustomResourceSingletonFunction(this,"Provider",{uuid:AwsCustomResource2.PROVIDER_FUNCTION_UUID,lambdaPurpose:"AWS",memorySize,timeout:props.timeout||cdk().Duration.minutes(2),role:props.role,...props.logRetention?{logRetention:props.logRetention}:{},logGroup:props.logGroup,functionName:props.functionName,vpc:props.vpc,vpcSubnets:props.vpcSubnets});this.grantPrincipal=provider.grantPrincipal;const installLatestAwsSdk=props.installLatestAwsSdk??this.node.tryGetContext(cxapi().AWS_CUSTOM_RESOURCE_LATEST_SDK_DEFAULT)??!0;installLatestAwsSdk&&props.installLatestAwsSdk===void 0&&core_1().Annotations.of(this).addWarningV2("@aws-cdk/custom-resources:installLatestAwsSdkNotSpecified",["installLatestAwsSdk was not specified, and defaults to true. You probably do not want this.",`Set the global context flag '${cxapi().AWS_CUSTOM_RESOURCE_LATEST_SDK_DEFAULT}' to false to switch this behavior off project-wide,`,"or set the property explicitly to true if you know you need to call APIs that are not in Lambda's built-in SDK version."].join(" "));const create=props.onCreate||props.onUpdate;if(this.customResource=new(cdk()).CustomResource(this,"Resource",{resourceType:props.resourceType||"Custom::AWS",serviceToken:provider.functionArn,serviceTimeout:props.serviceTimeout,pascalCaseProperties:!0,removalPolicy:props.removalPolicy,properties:{create:create&&this.formatSdkCall(create),update:props.onUpdate&&this.formatSdkCall(props.onUpdate),delete:props.onDelete&&this.formatSdkCall(props.onDelete),installLatestAwsSdk}}),props.policy){const statements=[];if(props.policy.statements.length!==0)for(const statement of props.policy.statements)statements.push(statement);else for(const call of[props.onCreate,props.onUpdate,props.onDelete])if(call&&call.assumedRoleArn==null){const statement=new(iam()).PolicyStatement({actions:[(0,sdk_info_1().awsSdkToIamAction)(call.service,call.action)],resources:props.policy.resources});statements.push(statement)}else if(call&&call.assumedRoleArn!=null){const statement=new(iam()).PolicyStatement({actions:["sts:AssumeRole"],resources:[call.assumedRoleArn]});statements.push(statement)}const policy=new(iam()).Policy(this,"CustomResourcePolicy",{statements});provider.role!==void 0&&policy.attachToRole(provider.role),this.customResource.node.addDependency(policy)}}getResponseFieldReference(dataPath){return AwsCustomResource2.breakIgnoreErrorsCircuit([this.props.onCreate,this.props.onUpdate],"getData"),this.customResource.getAtt(dataPath)}getResponseField(dataPath){return AwsCustomResource2.breakIgnoreErrorsCircuit([this.props.onCreate,this.props.onUpdate],"getDataString"),this.customResource.getAttString(dataPath)}formatSdkCall(sdkCall){const{logging,...call}=sdkCall,renderedLogging=(logging??logging_1().Logging.all())._render(this);return this.encodeJson({...call,...renderedLogging})}encodeJson(obj){return cdk().Lazy.uncachedString({produce:()=>cdk().Stack.of(this).toJsonString(obj)})}static{__runInitializers(_classThis,_classExtraInitializers)}};return AwsCustomResource2=_classThis})();exports.AwsCustomResource=AwsCustomResource;function includesPhysicalResourceIdRef(obj){if(obj===void 0)return!1;let foundRef=!1;return JSON.stringify(obj,(_,v)=>(v===PHYSICAL_RESOURCE_ID_REFERENCE&&(foundRef=!0),v)),foundRef}