🌐
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
(Optional) For Compatible runtimes, ... the --layers parameter, use the layer ARN. The ARN must specify the version (for example, arn:aws:lambda:us-east-1:123456789012:layer:my-layer:1)....
🌐
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 - AWS recommends the use of Cloud9 to do that as your custom layer must be compatible with Amazon Linux to function correctly on your lambda. But I find WSL satisfactory in MOST cases) For the demo, I'll just be following the example listed in the docs as it's very clear but I'll remove the clutter and share my own experience πŸ˜‰. 1- I'll make one directory to group everything I need for this task as follows: my-lambda |_ venv-python3.9 |_ python |_ lambda-layer.zip
Discussions

amazon web services - How to use AWS Lambda layer using Python? - Stack Overflow
Within lambda function navigate to the layers --> create a new layer --> out of 3 options, choose Specify an ARN and as the value put: arn:aws:lambda:eu-west-1:770693421928:layer:Klayers-python38-numpy:12. It will solve your problem and you will be able to work with numpy Namespace. More on stackoverflow.com
🌐 stackoverflow.com
Open Source Lambda Layers Repository
Naah, I wouldn't have that level of trust in get libraries published outside of PyPi. You can easily change part of the code, and for each call, get the environment variables and send the information in a request. More on reddit.com
🌐 r/aws
20
9
August 14, 2024
Where are AWS Published Lambda Layers, I am looking for Numpy, Scipy and Pandas Lambda Layer published by AWS? Are there one?

I have a script that does this inside Docker and outputs a zip you can upload as the layer: https://github.com/chedabob/LambdaZipper

EDIT: You may also need some bits from this if your layer relies upon shared libraries to be installed: https://github.com/chedabob/wkhtmltopdf-lambdalayer

More on reddit.com
🌐 r/aws
15
7
May 10, 2020
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
🌐
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 - Easiest Way to Create Lambda Layers with the Required Python Version A tutorial on using Amazon CloudShell to create lambda layers zip file. As a developer, I’ve always been excited about …
🌐
Capital One
capitalone.com β€Ί tech β€Ί cloud β€Ί creating-lambda-layers
Creating Lambda Layers for Python Functions | Capital One
June 1, 2023 - For example, your file could look like this: ... Then run your Docker container (optional, as described above). Replace my_layername with the name of your layer: docker run --name lambdalayer --rm --env HTTP_PROXY --env HTTPS_PROXY --env NO_PROXY --mount type=bind,source="$(pwd)"/my-layername,target=/var/task/lambdalayer -it aws-python3.9:local bash
🌐
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 - If you want a deep discussion about ... this library has other dependencies and could be a good sample. ... Navigate to Lambda > Layers and create a layer....
🌐
GitHub
github.com β€Ί mthenw β€Ί awesome-layers
GitHub - mthenw/awesome-layers: Ξ» A curated list of awesome AWS Lambda Layers. Sponsored by https://cloudash.dev Β· GitHub
ARN: arn:aws:lambda:us-east-1:251566558623:layer:python37-layer-pandas-gbq:1 Link: vbalasu/pandas-gbq-layer Includes pandas, a versatile data exploration tool that builds on numpy.
Starred by 2.3K users
Forked by 184 users
🌐
DEV Community
dev.to β€Ί aws-builders β€Ί mastering-aws-lambda-layers-build-deploy-and-manage-reusable-components-444c
Mastering AWS Lambda Layers: Build, Deploy, and Manage Reusable Components - DEV Community
June 2, 2025 - # Create a basic Lambda function aws lambda create-function \ --function-name url-shortener \ --runtime python3.12 \ --role arn:aws:iam::YOUR_ACCOUNT_ID:role/lambda-execution-role \ --handler lambda_function.lambda_handler \ --zip-file fileb://function.zip \ --description "My url-shortener function" Now you can attach this layer to any Lambda function:
🌐
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 - 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.
Find elsewhere
🌐
GitHub
github.com β€Ί keithrozario β€Ί Klayers
GitHub - keithrozario/Klayers: Python Packages as AWS Lambda Layers Β· GitHub
Using CDK, you can use the cdk-klayers package to help you pull in the latest layers for your Stack or App. from cdk_klayers import Klayers class MockStack(Stack): def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: super().__init__(scope, construct_id, **kwargs) runtime = aws_lambda.Runtime.PYTHON_3_12 # Initialize Klayers Class klayers = Klayers( self, python_version = runtime, region = "ap-southeast-1" ) # get the latest layer version for the requests package requests_layer = klayers.layer_version(self, "requests") lambda_function = aws_lambda.Function( self, 'HelloHandler', runtime=runtime, layers=[requests_layer], code=aws_lambda.Code.from_asset('lambda'), handler='hello.handler' )
Starred by 2.5K users
Forked by 351 users
Languages Β  Python 82.8% | HCL 15.2% | Dockerfile 1.9% | Shell 0.1%
🌐
Nordcloud
nordcloud.com β€Ί home β€Ί content hub β€Ί lambda layers for python runtime
Lambda layers for Python runtime - Nordcloud
January 30, 2025 - We'll show the second example. However, if you want to benefit from all the Lambda Layers advantages you should deploy it separately. service: tropoLayer package: individually: true provider: name: aws runtime: python3.6 layers: tropoLayer: path: build # Build directory contains all python dependencies compatibleRuntimes: # supported runtime - python3.6 functions: tropo_test: handler: handler.lambda_handler package: exclude: - node_modules/** - build/** layers: - {Ref: TropoLayerLambdaLayer } # Ref to the created layer.
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.

🌐
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 - Learn how to create an AWS Lambda layer for Python Requests module and make HTTP calls in your serverless application with ease.
🌐
Amazon Web Services
docs.aws.amazon.com β€Ί aws lambda β€Ί developer guide β€Ί managing lambda dependencies with layers
Managing Lambda dependencies with layers - AWS Lambda
When you create a new layer, Lambda ... to the function, you must specify the exact layer version you want to use (for example, arn:aws:lambda:us-east-1:123456789012:layer:my-layer:1)....
🌐
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
🌐
Amazon Web Services
docs.aws.amazon.com β€Ί aws lambda β€Ί developer guide β€Ί building lambda functions with python β€Ί working with .zip file archives for python lambda functions
Working with .zip file archives for Python Lambda functions - AWS Lambda
If your .zip file is located in a folder on your local build machine, use the --zip-file option to specify the file path, as shown in the following example command. aws lambda create-function --function-name myFunction \ --runtime python3.14 --handler lambda_function.lambda_handler \ --role arn:aws:iam::111122223333:role/service-role/my-lambda-role \ --zip-file fileb://myFunction.zip
🌐
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.
🌐
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 - The PYTHONUSERBASE environmental variable is cleared when the console session closes. This maintains a clean working environment. I later decide to use the requests package. Rather than update my layer, I leverage the work over at Klayers. Run the function update command an additional time while including both layers. The command is not additive – all desired layers must be declared. aws lambda update-function-configuration ` --function-name gitlab-dashboard ` --layers arn:aws:lambda:us-west-2:123456789012:layer:influxdb-client-python:1 arn:aws:lambda:us-west-2:770693421928:layer:Klayers-python38-requests:8
🌐
Harshad Ranganathan
rharshad.com β€Ί aws-lambda-layers-python
AWS Lambda Layers for Python – Harshad Ranganathan
February 29, 2020 - Let’s convert this into a lambda layer. Generic python library that enables to provision emr clusters with yaml config files (Configuration as Code) ... This project uses Pipfile for dependency management.
🌐
Amazon Web Services
docs.aws.amazon.com β€Ί aws lambda β€Ί developer guide β€Ί managing lambda dependencies with layers β€Ί adding layers to functions
Adding layers to functions - AWS Lambda
{ "Layers": [ { "LayerName": "my-layer", "LayerArn": "arn:aws:lambda:us-east-2:123456789012:layer:my-layer", "LatestMatchingVersion": { "LayerVersionArn": "arn:aws:lambda:us-east-2:123456789012:layer:my-layer:2", "Version": 2, "Description": "My layer", "CreatedDate": "2025-04-15T00:37:46.592+0000", "CompatibleRuntimes": [ "python3.14" ] } } ] } To list all layers in your account, omit the --compatible-runtime option. The response details show the latest version of each layer. You can also get the latest version of a layer using the ListLayerVersions API. For example, you can use the following list-layer-versions CLI command:
🌐
Amazon Web Services
docs.aws.amazon.com β€Ί aws lambda β€Ί developer guide β€Ί managing lambda dependencies with layers β€Ί packaging your layer content
Packaging your layer content - AWS Lambda
To ensure that Lambda picks up your layer content, your layer .zip file should have its dependencies in one of the following folder paths: The following examples show how you can structure the folders in your layer .zip archive. ... python/ # Required top-level directory └── requests/ └── boto3/ └── numpy/ └── (dependencies of the other packages)