DEV Community

Cover image for AWS Lambda Layer

AWS Lambda Layer

This is something I was stuck on while deploying the lambda function, even though the code was only a few 100 lines I had to deploy the function with a zip file including all the node dependencies unnecessarily, it was quite annoying and I'm having this feeling you felt the same way that why you landed over here.

Let's get started...

This is quite simple, it is made just for the problem I've discussed above i.e. Take away the dependencies and focus on code.

Official Definitions:
A Lambda layer is a .zip file archive that contains supplementary code or data. Layers usually contain library dependencies, a custom runtime, or configuration files.
If you are interested in reading more about it here's the link.

We can start using it now that we know what the lambda layer is.

STEP I
Search lambda in the service list and go to the layer on the left side.

Lambda Layer page on AWS

STEP II
Now we gonna create a package that we'll upload in layers

NOTICE: The path of the folders is important you can't mess this up otherwise it won't work. Different runtimes have different path like Im using node

My folder structure is like this

/layers
|------- /nodejs
            |----- /node_modules
            |----- package.json
            |----- package-lock.json
Enter fullscreen mode Exit fullscreen mode

If you wanna check out other runtime paths I suggest you should check the table given here

Make sure any modules you're adding are executable in Linux as lambda layers are executed in Amazon-Linux(Linux).

Now Zip the folder layers.zip or anything you wanna name it.

STEP III
Head towards the lambda page. Now we will upload the zip to lambda layers by creating a new layer.

Lambda layer creation page

Name the layer anything you want.
Don't forget to add the other details like architecture and runtime these 2 are the most important.
lambda layer detailed form

After you're done click on Create and done

Now you can attach this layer to any of your lambda functions and just call the package as you write normally. You don't have to do anything to integrate it. Enjoy the freedom of writing the code on the browser or make any changes to it on the go without worrying about the package or zipping it.

Thank you

Top comments (0)