Layers in Lambda function for Node JS

Shruti Tirpude
1 min readSep 17, 2020

Why Layers

1) Don’t want my lambda to be too big to see in console

2) Have all the node modules separate

3) Share the node modules

Layers in Lambda functions should be simple to use. I always thought just zip the node modules and upload it and it should work. AWS says Nooooooo….. we cannot make this simple for you.

So turn out that you have to have the exact nodejs folder and then node modules inside the same as shown below. Basically zip the“nodejs” folder else it will not work.

Folder Structure for the Layer

Once you upload the Layer (upload the zip package in Layers module in lambda) you can provide the arn of the layer to the lambda function. This makes your lambda function to be clean and not loaded with all the node modules.

AWS Documentation

https://docs.aws.amazon.com/en_us/lambda/latest/dg/configuration-layers.html

Folder structure defined in AWS Documentation

xray-sdk.zip
└ nodejs/node_modules/aws-xray-sdk

--

--

Shruti Tirpude

Software Engineer with an enthusiasm for AWS technologies like serverless.I enjoy solving real world complex problems through technology.