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.
Create an python.lambda.layer.Dockerfile.
FROM amazonlinux:latest
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
usr> docker build -f "python.lambda.layer.Dockerfile" -t lambdalayer:latest .
usr> docker run -it --name lambdalayer lambdalayer:latest bash
bash> python3.7 -m venv pandas
bash> source pandas/bin/activate
(pandas) bash> pip install pandas numpy requests -t ./python
(pandas) bash> deactivate
- Package
bash> zip -r python.zip ./python/usr> docker cp lambdalayer:python.zip
- Upload
Upload the python.zip file to your lambda layers.