diff --git a/packages/@aws-cdk/core/lib/custom-resource-provider/nodejs-entrypoint.ts b/packages/@aws-cdk/core/lib/custom-resource-provider/nodejs-entrypoint.ts index c90bf96e684cf..bf4a5642d3cf9 100644 --- a/packages/@aws-cdk/core/lib/custom-resource-provider/nodejs-entrypoint.ts +++ b/packages/@aws-cdk/core/lib/custom-resource-provider/nodejs-entrypoint.ts @@ -21,9 +21,27 @@ export type HandlerResponse = undefined | { NoEcho?: boolean; }; +/** + * Decodes encoded true/false values + */ +function decodeBooleans(object: object) { + return JSON.parse(JSON.stringify(object), (_k, v) => { + switch (v) { + case 'TRUE:BOOLEAN': + return true; + case 'FALSE:BOOLEAN': + return false; + default: + return v; + } + }); +} + export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent) { external.log(JSON.stringify(event, undefined, 2)); + event.ResourceProperties = decodeBooleans(event.ResourceProperties || { }); + // ignore DELETE event when the physical resource ID is the marker that // indicates that this DELETE is a subsequent DELETE to a failed CREATE // operation. diff --git a/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts b/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts index 17092538f32ca..b5c0058a3a0e7 100644 --- a/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts +++ b/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts @@ -330,7 +330,7 @@ export class AwsCustomResource extends cdk.Construct implements iam.IGrantable { pascalCaseProperties: true, encodeValues: true, properties: { - create: create, + create, update: props.onUpdate, delete: props.onDelete, }, diff --git a/packages/@aws-cdk/custom-resources/lib/provider-framework/runtime/framework.ts b/packages/@aws-cdk/custom-resources/lib/provider-framework/runtime/framework.ts index 2bd4116caa283..221af177a1b12 100644 --- a/packages/@aws-cdk/custom-resources/lib/provider-framework/runtime/framework.ts +++ b/packages/@aws-cdk/custom-resources/lib/provider-framework/runtime/framework.ts @@ -13,6 +13,22 @@ export = { [consts.FRAMEWORK_ON_TIMEOUT_HANDLER_NAME]: onTimeout, }; +/** + * Decodes encoded true/false values + */ +function decodeBooleans(object: object) { + return JSON.parse(JSON.stringify(object), (_k, v) => { + switch (v) { + case 'TRUE:BOOLEAN': + return true; + case 'FALSE:BOOLEAN': + return false; + default: + return v; + } + }); +} + /** * The main runtime entrypoint of the async custom resource lambda function. * @@ -26,7 +42,7 @@ export = { async function onEvent(cfnRequest: AWSLambda.CloudFormationCustomResourceEvent) { log('onEventHandler', cfnRequest); - cfnRequest.ResourceProperties = cfnRequest.ResourceProperties || { }; + cfnRequest.ResourceProperties = decodeBooleans(cfnRequest.ResourceProperties || { }); const onEventResult = await invokeUserFunction(consts.USER_ON_EVENT_FUNCTION_ARN_ENV, cfnRequest) as OnEventResponse; log('onEvent returned:', onEventResult);