One of the drawbacks of using a Lambda Layer is that you must declare it by its full version. This is a hassle as every time you update a Layer, you need to update its declaration in every stack to get the latest updates. It would be much better if one could specify it only by its name (similar as with the
FunctionName when declaring event source mapping). That is, instead of
arn:aws:lambda:us-east-1:123456789012:layer:my-layer:24 just use
I made a Cloudformation macro to do just that.
Uselatest scans through a Cloudformation template and replaces occurrences of Lambda Layers that are not fully qualified with an ARN of the latest available version of that Layer. This way you don’t have to think about updating a template after updating a Layer. The latest version will automatically get picked up during stack deployment. Magic. ✨
The macro works in all the places where you can declare a Layer. Check the Example section for more.
I wanted to make it available in the Serverless App Repo, but sadly, a Cloudformation Macro is not a supported resource. You’ll have to build, package and deploy it yourself if you want to use it.