Skip to content

Instantly share code, notes, and snippets.

@ola0x
Last active October 9, 2021 19:10
Show Gist options
  • Save ola0x/09d49f0ae63245ce44f6dadb4b9da3c5 to your computer and use it in GitHub Desktop.
Save ola0x/09d49f0ae63245ce44f6dadb4b9da3c5 to your computer and use it in GitHub Desktop.

Five easy steps to create a custom aws-lambda layer, this step is necessary if you use a mac-os or windows. This because the Lambda Layers which is an Amazon Linux environment.

Build

FROM amazonlinux:2.0.20191016.0 RUN yum install -y python37 &&
yum install -y python3-pip &&
yum install -y zip &&
yum clean all RUN python3.7 -m pip install --upgrade pip &&
python3.7 -m pip install virtualenv

Run the commands below to create your Dockerfile with a tag. usr> docker build -f ".Dockerfile" -t lambdalayer:latest .

Run Ur Docker image

usr> docker run -it --name lambdalayer lambdalayer:latest bash

Install

bash> python3.7 -m venv pandas bash> source pandas/bin/activate (pandas) bash> pip install pandas -t ./python (pandas) bash> deactivate

Package

bash> zip -r python.zip ./python/ usr> docker cp lambdalayer:python.zip ./Desktop/

Upload

Limitations of Lambda Layers

There are a few limitations that you need to be aware of and this includes: You can only use up to 5 layers per Lambda. The size of all your layers unzipped cannot exceed 250mb. Layers are mounted to the /opt directory in the function’s execution environment so be sure to Layer your functions properly if you are going to have more than one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment