Leveraging python’s robustness with AWS Lambda

A comprehensive guide on adding custom python libraries with AWS Lambda

Sriyash Kadu
2 min readSep 19, 2023

Are you just starting your journey with AWS Lambda and Python? You’ve probably realized that AWS Lambda’s default environment doesn’t include all the libraries you might need for your project. Don’t worry; we’re here to help you understand how to add external libraries to your AWS Lambda function in a simple and straightforward way.

In this beginner’s guide, we will walk you through the process step by step. By the end of this article, you’ll be able to enhance your Lambda functions with the power of external libraries.

Step 1: Understand Your Environment

Before we dive into the how-tos, let’s quickly understand AWS Lambda’s environment. Lambda uses Amazon Linux as its underlying operating system. So, any external libraries you add must be compatible with this environment.

Step 2: Prepare Your Library

First, you need to prepare your external library. From the official documentation website of the library download the .tar version of the entire package. Extract the package and compress the extracted contents again into a .zip.

Step 3: Adding the layer to AWS Lambda environment

AWS console

Add the layers name, the deployment package can be added from the local system(for packages above 10 MB, use AWS S3). Do select the relevant architectures as per the use-case. The relevant compatible runtimes are optional.

The newly added added layer can be added can be found under the “Custom layers”.

The custom layers are found here

Conclusion:

We can incorporate any library with adding it as a layer on our Lambda Python scripts and thereby increase the scope of our functions.

--

--

Sriyash Kadu
0 Followers

Cloud tech enthusiast and political writer, shaping bytes and ideas in the digital era.