When moving from EC2 to Lambda, one of the common trait in having node_modules all in a same lambda. Well, this practise has been long gone with the advent of Layers.
Layers lets you to install dependancies separately in a common pool and use it across different lambdas.
For example, I have 2 lambdas.
Lambda 1 - Reads a csv and saves it to DB
Lambda 2 - Reads a csv and sends email
Now, both has a dependancy package to read the .csv file. Let's say exceljs. If you need to install them in both the lambdas, don't you think you will do same for future lambdas also and its a wastage to do it everytime.
Instead, create a layer with your dependancies. Version them out and just update the layers.
Check out more about layers over here - https://docs.aws.amazon.com/lambda/latest/dg/chapter-layers.html
Top comments (0)