SAR-Lambda-Janitor
SAR-Lambda-Janitor copied to clipboard
feat: clean unused lambda layers
Hi,
I was using your serverless app and found it very helpful.
I think that it would be great to also clean up unused layer versions like it does with functions, hope you find this helpful too.
Thanks!
@JonaC22 thanks for doing this, let me take a look
@JonaC22 hey, sorry it took me a bit longer to find time to actually go through your PR. I think it looks fine, but I'm wondering if it's enough to keep only layer versions that are referenced by a function alias - e.g. if we say we're gonna keep the X most recent versions of functions, then these functions can reference layers that are no longer referenced by a function alias and are therefore subject to deletion.
And there're some optimizations we can do, since aliases (apart from $LATEST) ultimately point to a version, so for each function we just need to check:
- the versions we decide to keep
- the $LATEST alias
to find all the layer versions that we need to keep, and delete the rest
Hi @theburningmonk thank you for reviewing this.
Maybe the paremeter LayerVersionsToKeep
should be set to 0 by default, it would delete all layer versions that are not referenced as you suggest, then leave the possibility to change that parameter in case someone need most recent versions too.
What do you think?
Thanks!
Why not keep LayerVersionsToKeep
as it is - literally "we won't delete the most recent N versions", but older versions will be deleted if not referenced by a Lambda function version/$LATEST. That'll be consistent with how it handles Lambda function versions.
@theburningmonk Ok, great! Sorry I misunderstood what you said. I will change the code to skip the lambda layers referenced by version instead of by alias
Thanks!
Hi @theburningmonk I've pushed the changes, can you please review it again? Thanks!