Skip to content

Commit

Permalink
add decode booleans to runtime code
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardomourar committed Jun 18, 2020
1 parent 8b582d3 commit e8bf3aa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
Expand Down

0 comments on commit e8bf3aa

Please sign in to comment.