INNER CODE UNIT · JavaScript
cloudformationCustomResourceMiddlewareAfter
middyjs/middy · packages/cloudformation-response/index.js:32
const cloudformationCustomResourceMiddlewareAfter = async (request) => {
let { response } = request;
response ??= {};
// The response is a field map; a string, number or array can't carry
// Status and friends, and would fail with "Cannot create property".
if (typeof response !== "object" || Array.isArray(response)) {
throw new TypeError(`${pkg}: handler response must be an object`, {
cause: {
package: pkg,
data: { type: Array.isArray(response) ? "array" : typeof response },
},
});
}
response.Status ??= "SUCCESS";
// Reason is required when Status is FAILED.
if (response.Status === "FAILED") response.Reason ??= "See CloudWatch logs";
response.RequestId ??= request.event.RequestId;
response.LogicalResourceId ??= request.event.LogicalResourceId;