🌐
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.
🌐
Medium
medium.com β€Ί brlink β€Ί how-to-create-a-python-layer-in-aws-lambda-287235215b79
How to Create a Python Layer in Aws Lambda | by Rafael Campana | BRLink | Medium
December 2, 2021 - I will create a sample using pandas, once this library has other dependencies and could be a good sample. ... Navigate to Lambda > Layers and create a 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
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
Help with Python Lambda Layers needed: Imports within a module fail unless also imported in the Lambda code.
OKay so the solution was the final paragraph of section 6.4.1 of the Modules tutorial: https://docs.python.org/3/tutorial/modules.html#packages Remember, there is nothing wrong with using from package import specific_submodule! In fact, this is the recommended notation unless the importing module needs to use submodules with the same name from different packages. Replacing from mymodule import subfolder with from mymodule.subfolder import ( mysubmodule ... ) solved my problem. Still not sure why the other way passed unit testing and local testing, but it is what it is. Now I'm using best practices so it's an overall improvement regardless. More on reddit.com
🌐 r/aws
3
3
March 3, 2023
How to create Lambda layer for python3.7

You’re really close. Google how to apt install Python 3.7.

Also why not just use 3.9 or whatever is shipped with apt install python3.

More on reddit.com
🌐 r/awslambda
3
2
September 6, 2022
🌐
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
🌐
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 - Its important you create a directory named python. This is mandatory when working with lambda layers. Now that you are in python directory, install the required libraries. ... We will need to zip the python folder where the library is but before we do that, let’s save space and delete objects with β€œ.dis-info” extension from the folder.
🌐
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.
🌐
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.
🌐
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>
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,

🌐
AWS re:Post
repost.aws β€Ί knowledge-center β€Ί lambda-python-function-layer
How can I create a layer for my Lambda Python function?
February 7, 2023 - From the python-lambda-layer-creation Applications settings, select I acknowledge that this app creates custom IAM roles, and then choose Deploy. You can create a layer to invoke your Lambda function and pass a list of dependencies included ...
🌐
Plain English
plainenglish.io β€Ί blog β€Ί create-your-own-python-layer-on-aws-lambda-environment-2e5160b66f17
Create your own Python Layer in AWS Lambda Environment
April 9, 2021 - Import your custom Layer from any lambda function. I'll use the Rice n' Beans from the pythonic world as the example libraries, pandas and NumPy. This step should be very simple once you can execute anywhere you'd like. In the following lines of code, we are installing all packages placed on a .txt file which is on the same directory where the command will be executed (the good old requirements.txt). $ python3 -m pip install -r requirements.txt -t ./python
🌐
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 - We will create the layer using an EC2 Instance that will be provisioned by IaC (CloudFormation). I know what you are thinking. Why do we need an EC2 Instance to simply create a Lambda Layer? Why not just do it locally? The architecture for a Python Lambda Layer requires a Linux OS.
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
🌐
Nicolasneudeck
nicolasneudeck.com β€Ί blog β€Ί aws-python-lambda-layer
Creating and Deploying Custom Lambda Layers for Python Functions | Nicolas Neudeck
A step-by-step guide on creating and deploying custom AWS Lambda layers to include additional Python dependencies, featuring a bash script for building layers locally.
🌐
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...
🌐
Medium
jainsaket-1994.medium.com β€Ί creating-a-lambda-function-layer-in-python-without-using-ec2-using-cloudshell-399614a4e3ce
Create AWS Lambda Layers for Python Packages | by π’πšπ€πžπ­ π‰πšπ’π§ | Medium
October 9, 2023 - Create a ZIP archive of the python folder using the following command (replace my-layer.zip with your desired layer name): ... On the right side, locate the β€œActions” button. Under β€œActions,” click on β€œDownload file.” ... Use the absolute path. You can copy the file path from the command-line and paste it below. ... Use the AWS Command Line Interface (CLI) to publish your Lambda Layer using the AWS CloudShell terminal.
🌐
Medium
medium.com β€Ί @shivkaundal β€Ί how-to-create-and-use-aws-lambda-layers-a-step-by-step-tutorial-424c762bbdbf
How to Create and Use AWS Lambda Layers: A Step-by-Step Tutorial | by Shiv Pal Singh Kaundal | Medium
March 31, 2025 - Follow these steps to create a deployment package: First, create a folder to organize the function and its dependencies: ... Inside this folder, create a Python file (e.g., lambda_function.py) and paste the code provided before.
🌐
DEV Community
dev.to β€Ί razcodes β€Ί how-to-create-a-lambda-layer-in-aws-106m
How to create a lambda layer in AWS - DEV Community
May 10, 2020 - That folder structure is important because that is where Python expects to find the modules. Also as you can see, in this example I am using Python 3.8. Now we can go into the lambda-layer folder and create a zip file for the layer that will be uploaded using the console.
🌐
Medium
medium.com β€Ί the-cloud-architect β€Ί getting-started-with-aws-lambda-layers-for-python-6e10b1f9a5d
Getting started with AWS Lambda Layers for Python | by Adrian Hornsby | The Cloud Engineer | Medium
June 1, 2023 - 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. First, let’s create a file called custom_func.py and write a dummy function in it that ...
🌐
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.