Prune your Lambda Functions

By Daniel Aniszkiewicz ยท 8 February, 2022


When working on projects when we use AWS Lambda, we often change the code that is there. With each deployment, Lambda creates a new version of your function each time that you publish the function.

When we enter a particular Lambda in the AWS console, and click on Versions tab, we can see how many versions of that particular Lambda we have.


As you can see, in my case it's a lot of versions that I don't need ๐Ÿ˜….

It is also worth remembering that Serverless Framework, does not automatically remove previous versions of lambda. Fortunately, there is a plugin for that - Serverless Prune Plugin.

The plugin is very easy to use, we can both manually delete n-last versions or set prune automatically. (It's useful, that the plugin can also prune lambda layers, as well the possibility to run dry run without actually performing the pruning operations).

For most cases this config within the SLS should be fine:

Simple, right?