Many developers face issues when importing custom modules on AWS Lambda, you see errors like “No module named pandas” or “No module named numpy”, and most times, the easiest ways to solve this is to bundle your lambda function code with the module and deploy it on AWS lambda which at the end makes the whole project large and doesn’t give room for flexibility. To solve this problem, we use something called **Layers **on AWS Lambda.

What are Layers?

According to the docs, A layer is a ZIP archive that contains libraries, a custom runtime, or other dependencies. With layers, you can use libraries in your function without needing to include them in your deployment package.

Layers let you install all the modules you need for your application to run, it provides that flexibility for you deploy your lambda function and even with layers you can even make your own custom code and add external functionality as a layer itself. It saves you the stress of managing packages and allows you to focus more on your code.

Benefits of Layers

  • Makes your deployment package smaller and easily deployable
  • The layer can also be used across other lambda functions.
  • Make code changes quickly on the console.
  • Lambda layers enable versioning, which allows you to add more packages and also use previous package versions when needed.

Now that we know what layers and see how useful it is, let’s build one

#serverless #aws-lambda #aws #python

How to Build Custom Layers on AWS Lambda
4.10 GEEK