diff --git a/lib/plugins/aws/custom-resources/resources/utils.js b/lib/plugins/aws/custom-resources/resources/utils.js index 29cca49a9..332f1dcf2 100644 --- a/lib/plugins/aws/custom-resources/resources/utils.js +++ b/lib/plugins/aws/custom-resources/resources/utils.js @@ -73,16 +73,30 @@ function getEnvironment(context) { }; } +// function handlerWrapper(handler, PhysicalResourceId) { +// return async (event, context, callback) => { +// // extend the `event` object to include the PhysicalResourceId +// event = Object.assign({}, event, { PhysicalResourceId }); +// return Promise.resolve(handler(event, context, callback)) +// .then( +// (result) => response(event, context, 'SUCCESS', result), +// (error) => response(event, context, 'FAILED', {}, error) +// ) +// .then((result) => callback(null, result), callback); +// }; +// } function handlerWrapper(handler, PhysicalResourceId) { - return async (event, context, callback) => { - // extend the `event` object to include the PhysicalResourceId + return async (event, context) => { // Removed callback parameter event = Object.assign({}, event, { PhysicalResourceId }); - return Promise.resolve(handler(event, context, callback)) - .then( - (result) => response(event, context, 'SUCCESS', result), - (error) => response(event, context, 'FAILED', {}, error) - ) - .then((result) => callback(null, result), callback); + + try { + const result = await handler(event, context); + await response(event, context, 'SUCCESS', result); + return result; + } catch (error) { + await response(event, context, 'FAILED', {}, error); + throw error; + } }; }