AWS remove unused Lambda versions

 AWS provides the ability to version Lambdas and assign versions to Aliases, which can be beneficial when managing Lambdas with environments.  For more in depth information, please refer to AWS documentation for Lambda-Versioning-Aliases

Each version of a Lambda consumes code storage space allocated by AWS, and depending on how many Lambdas, Versions, and your code size, this can quickly deplete your available storage.  Our current workflow utilizing Lambdas does not require us to retain previous versions of Lambdas as our deployment process is capable of re-deploying previous code and creating a new version of the Lambda.  We had some Lambdas with over 500 versions, and our code storage was at 77% capacity.

To help maintain our Lambdas and remove previous versions, I created a Lambda (ironic, huh?) that will delete any versions that are not assigned to an Alias.    After running the cleanup Lambda, our utilization was reduced to a mere 3%!!

The code can be found in my GitHub repo,  Lambda-Version-Cleanup

Leave a Reply

Your email address will not be published.