aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 7.96 kB
JavaScript
var _a,_b,_c,_d;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},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{constructor(){this.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,_a=JSII_RTTI_SYMBOL_1,PhysicalResourceIdReference[_a]={fqn:"aws-cdk-lib.custom_resources.PhysicalResourceIdReference",version:"2.185.0"};class PhysicalResourceId{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,_b=JSII_RTTI_SYMBOL_1,PhysicalResourceId[_b]={fqn:"aws-cdk-lib.custom_resources.PhysicalResourceId",version:"2.185.0"};class AwsCustomResourcePolicy{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,_c=JSII_RTTI_SYMBOL_1,AwsCustomResourcePolicy[_c]={fqn:"aws-cdk-lib.custom_resources.AwsCustomResourcePolicy",version:"2.185.0"},AwsCustomResourcePolicy.ANY_RESOURCE=["*"];class AwsCustomResource extends constructs_1().Construct{static breakIgnoreErrorsCircuit(sdkCalls,caller){for(const call of sdkCalls)if(call?.ignoreErrorCodesMatching)throw new Error(`\`${caller}\` cannot be called along with \`ignoreErrorCodesMatching\`.`)}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,AwsCustomResource),error}if(!props.onCreate&&!props.onUpdate&&!props.onDelete)throw new Error("At least `onCreate`, `onUpdate` or `onDelete` must be specified.");if(!props.role&&!props.policy)throw new Error("At least one of `policy` or `role` (or both) must be specified.");if(props.onCreate&&!props.onCreate.physicalResourceId)throw new Error("'physicalResourceId' must be specified for 'onCreate' call.");if(!props.onCreate&&props.onUpdate&&!props.onUpdate.physicalResourceId)throw new Error("'physicalResourceId' must be specified for 'onUpdate' call when 'onCreate' is omitted.");for(const call of[props.onCreate,props.onUpdate,props.onDelete])call?.physicalResourceId?.responsePath&&AwsCustomResource.breakIgnoreErrorsCircuit([call],"PhysicalResourceId.fromResponse");if(includesPhysicalResourceIdRef(props.onCreate?.parameters))throw new Error("`PhysicalResourceIdReference` must not be specified in `onCreate` parameters.");this.props=props;let memorySize=props.memorySize;props.installLatestAwsSdk&&(memorySize??(memorySize=512));const provider=new(aws_custom_resource_provider_generated_1()).AwsCustomResourceSingletonFunction(this,"Provider",{uuid:AwsCustomResource.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 AwsCustomResource.breakIgnoreErrorsCircuit([this.props.onCreate,this.props.onUpdate],"getData"),this.customResource.getAtt(dataPath)}getResponseField(dataPath){return AwsCustomResource.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)})}}exports.AwsCustomResource=AwsCustomResource,_d=JSII_RTTI_SYMBOL_1,AwsCustomResource[_d]={fqn:"aws-cdk-lib.custom_resources.AwsCustomResource",version:"2.185.0"},AwsCustomResource.PROVIDER_FUNCTION_UUID="679f53fa-c002-430c-b0da-5b7982bd2287";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}
;