Getting started with AWS Lambda Layers for Python

Adrian Hornsby
The Cloud Architect
5 min readDec 27, 2018

--

You want to avoid errors that can occur when you install and package dependencies with your function code? You want to keep your deployment package smaller and cleaner? Right, me too!

Say hello to Lambda Layers! With Lambda Layers, you can configure your Lambda function to import additional code without including it in your deployment package.

Let me explain — A Layer is a ZIP archive that contains libraries and other dependencies that you can import at runtime for your lambda functions to use. It is especially useful if you have several AWS Lambda functions that use the same set of functions or libraries — you know, code reuse :-)

Since I build most of my experiments in python, I want to show you a small example of using Layers in Python :-)

Before we get started, it is very important to understand that when a Layer ZIP archive is loaded into AWS Lambda, it is unzipped to the /opt folder. For your Python lambda function to import the libraries contained in the Layer, the libraries should be placed under the python sub-directory of the /opt folder. For other supported runtimes, check here.

Let’s get started!

First, let’s create a file called custom_func.py and write a dummy function in it that will print out “Hello from…

--

--

Adrian Hornsby
The Cloud Architect

Principal System Dev Engineer @ AWS ☁️ I break stuff .. mostly. Opinions here are my own.