🌐
Amazon Web Services
docs.aws.amazon.com β€Ί aws lambda β€Ί developer guide β€Ί building lambda functions with python β€Ί working with layers for python lambda functions
Working with layers for Python Lambda functions - AWS Lambda
Create the layer in Lambda. Add the layer to your functions. ... To create a layer, bundle your packages into a .zip file archive that meets the following requirements: Build the layer using the same Python version that you plan to use for the Lambda function.
🌐
DEV Community
dev.to β€Ί fadygrab β€Ί how-to-make-an-aws-lambda-custom-layer-for-python-3h6g
How to make an AWS Lambda custom layer for python - DEV Community
March 25, 2023 - ... This will produce the lambda-layer.zip file that I'll upload. 6- Now for the AWS stuff, in order to upload your custom layer, we will do the following: 1- Navigate to Layers form the left navigation bar then press create layer
Discussions

Best way to build a python lambda layer?
I would do it in the AWS lambdaci/lambda docker image. While very similar to the Amazon Linux distros, the Lambda runtimes are somewhat different, and the docker images are the Lambda runtimes. I ran into trouble once building a crypto library as you suggest...wouldn't work when I loaded it into the Lambda layer, but once I did the docker image, no issue at all. https://hub.docker.com/r/lambci/lambda/ More on reddit.com
🌐 r/aws
3
1
January 4, 2021
amazon web services - How to use AWS Lambda layer using Python? - Stack Overflow
I'm not saying it's relevant in ... huge Python packages like Pandas, then I would avoid trying to use them in Lambda. ... I've seen that a few libraries like numpy and pandas don't work in Lambda when installed using pip. I have had success using the .whl package files for these libraries to create the Lambda layer... More on stackoverflow.com
🌐 stackoverflow.com
python - How to create a layer in lambda function - Stack Overflow
Steps followed to create Create a virtual environment and activate it pip install elasticsearch Zip the folder inside site-packages.zip 4.Create Layer in AWS (say name is elastic) Add the code b... More on stackoverflow.com
🌐 stackoverflow.com
Lambda Layers and CDK
Lambda layers is one of those features that _seem_ useful and turns out to be a nightmare in practice. Say for instance you keep your layers and functions using cloudformation. IaC, sane enough idea. layer L v1 is up. You deploy lambda A using it, all good and working. You update L so now it's v2. Next stack update for A has an issue, unrelated to the layer. Anything, random aws hiccup. The deployment rolls back. Ops, L v1 no longer exists, rollback failed, stack stuck.... Remove it all and do it again.... More on reddit.com
🌐 r/aws
21
8
May 16, 2024
🌐
Capital One
capitalone.com β€Ί tech β€Ί cloud β€Ί creating-lambda-layers
Creating Lambda Layers for Python Functions | Capital One
June 1, 2023 - Uploading a layer using the console is easy. Just go to the Lambda service, choose Layers, click on Create Layer, then follow the prompts. I prefer using the CLI. You can use the following command, replacing my-layername with your own layer name.
🌐
Medium
aws.plainenglish.io β€Ί easiest-way-to-create-lambda-layers-with-the-required-python-version-d205f59d51f6
Easiest Way to Create Lambda Layers with the Required Python Version | by Amit Duwal | AWS in Plain English
December 23, 2024 - Seamless Integration: CloudShell integrates seamlessly with other AWS services, simplifying the process of uploading files to S3 and creating Lambda Layers. Below are the steps to create a Layer ZIP file in CloudShell: ... Log in to the AWS Management Console. Click on CloudShell icon left of the notification icon ... Wait for the the terminal to load. The default version of cloudshell is python 3.9.
🌐
Amazon Web Services
docs.aws.amazon.com β€Ί aws lambda β€Ί developer guide β€Ί managing lambda dependencies with layers
Managing Lambda dependencies with layers - AWS Lambda
For more information, see Working with Lambda layers and extensions in container images ... To create a layer, package your dependencies into a .zip file, similar to how you create a normal deployment package.
🌐
DEV Community
dev.to β€Ί rishabdugar β€Ί creating-aws-lambda-layers-for-python-runtime-a-complete-guide-3gi0
The Best Way to Create AWS Lambda λ Layers for Python 🐍 (Fast & Easy) : A Complete Guide - DEV Community
January 17, 2025 - Go to Lambda > Layers and click Create Layer. Upload the python_layer.zip file, select the compatible runtime (e.g., Python 3.12), and save the layer.
🌐
Keyq
keyq.cloud β€Ί en β€Ί blog β€Ί creating-an-aws-lambda-layer-for-python-requests-module
Creating an AWS Lambda Layer for Python Requests Module
January 30, 2024 - From the Layers page, click on the orange "Create layer" button to open the creation wizard. Specify a name for your new layer and a description so you know what this layer is. Select the "Upload a .zip file" option as we will be uploading the ...
Find elsewhere
🌐
Reddit
reddit.com β€Ί r/aws β€Ί best way to build a python lambda layer?
r/aws on Reddit: Best way to build a python lambda layer?
January 4, 2021 -

There are lots of different articles online describing ways to build dependency layers for python lambda functions. Is the definitive way to build a lambda layer with packages that will work to do the following:

  1. spin up a (linux) EC2

  2. build a virtualenv and source it

  3. pip install the packages you want

  4. download the /pythonx.x/ directory and zip it

  5. upload it as a lambda layer

This seems to be the most common recommendation, but I wanted to know what the actual best practice is for doing this. Thanks,

🌐
Medium
aws.plainenglish.io β€Ί lambda-layer-how-to-create-them-python-version-bc1e027c5fea
Lambda Layer : how to create them? β€” python version. | AWS in Plain English
August 21, 2024 - Now that zip file is the file you will need to upload to the AWS Lambda layers. Join Medium for free to get updates from this writer. ... One small note to add here , is that because AWS Lambda are running on Linux and sometimes β€” well in my case I was installing the packages on Mac OS β€” and sometimes because the binaries included in the deployment package were built for a platform other than Linux, you might be getting the below error ... apt-get update && apt-get install -y -qq python3-pip git \ && cd /usr/local/bin && ln -s /usr/bin/python3 python \ && python3 -m pip install --upgrade pip \ && python3 -m pip install ipython \ && rm -rf /var/lib/apt/lists/* apt-get update && apt-get install zip
🌐
LinkedIn
linkedin.com β€Ί pulse β€Ί quick-tutorial-creating-aws-lambda-layer-pak-hun-chan
Quick Tutorial - Creating an AWS Lambda Layer
July 28, 2022 - Here is my quick guide on how to create a Lambda layer (with the PyMySQL library as an example): Step 1: Download the library onto your local environment Β· For my project, I needed the pymysql library, so I entered the following command: ... This places the pymysql library into a folder named "python...
🌐
YouTube
youtube.com β€Ί watch
AWS Lambda Layers Step by Step Tutorial | Python Libraries Management - YouTube
In this tutorial, I provided a step by step instruction on how to create lambda layers with pandas and requests using docker, and how to use them in a lambda...
Published Β  June 10, 2022
🌐
AWS re:Post
repost.aws β€Ί knowledge-center β€Ί lambda-python-function-layer
Create a layer for a Lambda Python function | AWS re:Post
February 7, 2023 - Select Show apps that create custom IAM roles or resource policies. In the search pane, enter python-lambda-layer-creation.
🌐
Wahl Network
wahlnetwork.com β€Ί home β€Ί how to create aws lambda layers for python
How to Create AWS Lambda Layers for Python - Wahl Network
November 23, 2022 - In this post, I review how to setup Python for Windows and describe my use case scenario for needing Lambda layers for Python. I then deep dive into installing a Python package to a custom location, creating a zip file with all necessary packages and libraries, publishing the zipped code to an AWS Lambda layer, and associating the layer to an AWS Lambda function.
🌐
Nicolasneudeck
nicolasneudeck.com β€Ί blog β€Ί aws-python-lambda-layer
Creating and Deploying Custom Lambda Layers for Python Functions | Nicolas Neudeck
Choose Python 3.12 as Compatible runtime. Click Create. Copy the ARN of the newly created layer. Go to the Lambda Functions page in the AWS Lambda console.
Top answer
1 of 3
1

I've seen that a few libraries like numpy and pandas don't work in Lambda when installed using pip. I have had success using the .whl package files for these libraries to create the Lambda layer. Refer to the steps below:

NOTE: These steps set up the libraries specific to the Python 3.7 runtime. If using any other version, you would need to download the .whl files corresponding to that Python version.

  1. Create an EC2 instance using Amazon Linux AMI and SSH into this instance. We should create our layer in Amazon Linux AMI as the Lambda Python 3.7 runtime runs on this operating system (doc).

  2. Make sure this instance has Python3 and "pip" tool installed.

  3. Download the numpy .whl file for the cp37 Python version and the manylinux1_x86_64 OS by executing the below command:

$ wget https://files.pythonhosted.org/packages/d6/c6/58e517e8b1fb192725cfa23c01c2e60e4e6699314ee9684a1c5f5c9b27e1/numpy-1.18.5-cp37-cp37m-manylinux1_x86_64.whl
  1. Skip to the next step if you're not using pandas. Download the pandas .whl file for the cp37 Python version and the manylinux1_x86_64 OS by executing the below command:
$ wget https://files.pythonhosted.org/packages/a4/5f/1b6e0efab4bfb738478919d40b0e3e1a06e3d9996da45eb62a77e9a090d9/pandas-1.0.4-cp37-cp37m-manylinux1_x86_64.whl
  1. Next, we will create a directory named "python" and unzip these files into that directory:
        $ mkdir python
        $ unzip pandas-1.0.4-cp37-cp37m-manylinux1_x86_64.whl -d python/
        $ unzip numpy-1.18.5-cp37-cp37m-manylinux1_x86_64.whl -d python/
  1. We also need to download "pytz" library to successfully import numpy and pandas libraries:
        $ pip3 install -t python/ pytz
  1. Next, we would remove the β€œ*.dist-info” files from our package directory to reduce the size of the resulting layer.
        $ cd python
        $ sudo rm -rf *.dist-info
  1. This will install all the required libraries that we need to run pandas and numpy.

  2. Zip the current "python" directory and upload it to your S3 bucket. Ensure that the libraries are present in the hierarchy as given here.

        $ cd ..
        $ zip -r lambda-layer.zip python/
        $ aws s3 cp lambda-layer.zip s3://YOURBUCKETNAME
  1. The "lambda-layer.zip" file can then be used to create a new layer from the Lambda console.
2 of 3
0

Base on aws lamda layer doc, https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html your zip package for the layer must have this structure.

my_layer.zip
  | python/numpy
  | python/numpy-***.dist-info

So what you have to do is create a folder python, and put the content of site-packages inside it, then zip up that python folder. I tried this out with a simple package and it seem to work fine.

Also keep in mind, some package require c/c++ compilation, and for that to work you must install and package on a machine with similar architecture to lambda. Usually you would need to do this on an EC2 where you install and package where it have similar architecture to the lambda.

🌐
Pybites
pybit.es β€Ί articles β€Ί guest-create-aws-lambda-layers
How to Create an AWS Lambda Layer For Any Python Dependency – Pybites
Once the process has finished, you can see your zip file in the S3 bucket. Time to create our Lambda layer! $ aws lambda publish-layer-version \ --layer-name scikit-learn \ --description "Scikit-learn for Python 3.8" \ --compatible-runtimes python3.7 python3.8 \ --content S3Bucket=<name-of-your-bucket>
🌐
DEV Community
dev.to β€Ί aws-builders β€Ί how-to-create-a-python-lamda-layer-509j
How to create a Python Lambda Layer? - DEV Community
November 16, 2022 - In this article I intend to explain what a Lambda Layer is, the benefits of it, and lastly, how to create a Layer for a Python Lambda function.
🌐
DEV Community
dev.to β€Ί aws-builders β€Ί create-open-cv-python-layer-for-aws-lambda-hcj
Create open-cv Python layer for AWS Lambda - DEV Community
July 16, 2025 - Use opencv-python-headless instead of the standard opencv-python package since Lambda doesn't need GUI components, the size of the layer will be reduced a lot which is good. pip3 install --platform manylinux2014_x86_64 --implementation cp --python-version 3.11 --only-binary=:all: --upgrade --target python/lib/python3.11/site-packages/ opencv-python-headless Β· Then you will have a folder look liek this, for this one I use Python 3.11: Create a ZIP file of the layer contents.
Top answer
1 of 4
6

If I may, I would like to recommend an alternative technique which has never failed me. The technique includes docker tool described in the recent AWS blog:

  • How do I create a Lambda layer using a simulated Lambda environment with Docker?

Thus for this question, I verified it using elasticsearch as follows:

  1. Create empty folder, e.g. mylayer.

  2. Go to the folder and create requirements.txt file with the content of

elasticsearch
  1. Run the following docker command (may adjust python version to your needs):
docker run -v "$PWD":/var/task "lambci/lambda:build-python3.8" /bin/sh -c "pip install -r requirements.txt -t python/lib/python3.8/site-packages/; exit"
  1. Create layer as zip:
zip -r elastic.zip python > /dev/null
  1. Create lambda layer based on elastic.zip in the AWS Console. Don't forget to specify Compatible runtimes to python3.8.

  2. Test the layer in lambda using the following lambda function:

import json

from elasticsearch import Elasticsearch, RequestsHttpConnection

def lambda_handler(event, context):
    # TODO implement
    
    print(dir(Elasticsearch))
    
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

The function executes correctly:

['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'bulk', 'clear_scroll', 'close', 'count', 'create', 'delete', 'delete_by_query', 'delete_by_query_rethrottle', 'delete_script', 'exists', 'exists_source', 'explain', 'field_caps', 'get', 'get_script', 'get_script_context', 'get_script_languages', 'get_source', 'index', 'info', 'mget', 'msearch', 'msearch_template', 'mtermvectors', 'ping', 'put_script', 'rank_eval', 'reindex', 'reindex_rethrottle', 'render_search_template', 'scripts_painless_execute', 'scroll', 'search', 'search_shards', 'search_template', 'termvectors', 'update', 'update_by_query', 'update_by_query_rethrottle']
2 of 4
0

As one option is already mentioned by @Marcin which is required Docker to be installed in the target machine. If you want to skip docker then you can use below script to create and publish layer to AWS.

All you need

./creater_layer.sh <package_name> <layer_name>

./creater_layer.sh elasticsearch my-layer

script creater_layer.sh

path="app"
package="${1}"
layername="${2}"
mkdir -p $path
pip3 install "${package}" --target "${path}/python/lib/python3.8/site-packages/"
cd $path && zip -r ../lambdalayer.zip .
aws lambda publish-layer-version --layer-name "${layername}" --description "My layer" --license-info "MIT" --zip-file "fileb://../lambdalayer.zip" --compatible-runtimes python3.8