Helper library for Lambda function as a backend of CloudFormation custom resource.
Can be combined with Serverless Framework.
See example which creates a S3 object as an custom resource.
npm install --save cfn-custom-resource-helper
const {cfnCustomResource} = require("cfn-custom-resource-helper");
module.exports.cfnCustomResource = (event, context, callback) => {
cfnCustomResource(event, context, {
onCreate() {
/* Code to create resource goes here. */
/* Please return Promise<{id: "**PhysicalResourceId**", data?: { <data to reference with Fn::GetAtt> }}> */
},
onUpdate() {
/* Code to update resource goes here. */
/* Please return Promise<{id: "**PhysicalResourceId**", data?: { <data to reference with Fn::GetAtt> }}> */
},
onDelete() {
/* Code to delete resource goes here. */
/* Please return Promise<{id: "**PhysicalResourceId**", data?: { <data to reference with Fn::GetAtt> }}> */
},
}).then(result => {
callback(undefined, result);
}).catch(err => {
callback(err);
});;
};
If you use Serverless framework, you can define additional resource on serverless.yml
.