Currently migrating my blog from wordpress and other scattered sources.

Creating Layers in AWS Lambda

This is a microblog explaining how to add a layer to lambda function in AWS.

We might have to import a set of libraries [eg: numpy, pandas etc…] into your lambda function and it is often easier to provide these libraries as layers. We can attach these layers to lambda function and import them to your lambda function seemlessly. Here is the snapshot of limitations associated with lambda functions.

Step-1

Install the library[ies] to local folder. Here I have shown how to create a layer with Pyyaml

mkdir python
pip install "pyyaml==5.0" -t ./python
pip install "numpy==1.20.0" -t ./python

Step-2

Zip the folder and upload as layer in AWS lambda. You will have to add this layer when defining a lambda function to have the library accessible in lambda functions.

zip -r pyyaml_numpy_layer.zip python

If there are other sub directories in the ./python folder of the layer then the modules might not be picked up by the function. We would need to update PYHTONPATH or sys.path to make it look it into the subdirectories.

References

  1. lambda documentation