jsoninstanceaws-lambdaaws-cloudformationaws-opsworks

Delete the backing Lambda function for a Lambda-backed custom resource


I have an AWS CloudFormation template that creates an OpsWorks stack and deploys an application. To deploy the application, I am using a Lambda function and a custom resource which utilizes that function. My problem is: that Lambda function will only be executed one time during the creation of the stack, and then it will never be used again. Is there any way to delete the Lambda function by AWS CloudFormation at the end of the execution of the stack?


Solution

  • First, I should say Aditya is right, you shouldn't delete the backing Lambda as it's used throughout the lifecycle.

    However, if you really really want to do it, one way is to simply have the function delete itself (and related resources, eg, role) after running.