A docker-based utility to create lambda layer packages for Python runtime on demand.
- Docker desktop
Clone this repo & follow the steps in windows-commands.bat
-
Build Docker Image from Dockerfile
docker build -t layer-builder-image .
-
Run a Container from the Image
docker run -td --name=layer-builder layer-builder-image
-
Update
requirements.txt
(local) to list the libraries and versions your project needs. Example:pandas==1.4.2 requests==2.27.1
-
Copy
requirements.txt
from host to containerdocker cp .\requirements.txt layer-builder:/
-
Run
install.sh
inside the containerdocker exec -i layer-builder /bin/bash < ./install.sh
-
This script performs the following steps:
- creates and activates a python virtualenv
- installs the requested libraries (requirements.txt) from pip
- creates a zip file named
python.zip
with all installed packages
-
Copy the
python.zip
thus created from container to hostdocker cp layer-builder:/python.zip python.zip
-
Stop and delete the container
docker stop layer-builder docker rm layer-builder
-
โ ๏ธ Do NOT rename the zip file. AWS Lambda needs the file to be namedpython.zip
. This zip file can be uploaded to AWS console when creating a new AWS Lambda Layer.๐ก Tip: For storing the zip file for future usage, since you cannot rename the zip file, you can instead create a folder with a descriptive name that describes the contents of the
python.zip
and move the zip file to that folder. You may also choose to place therequirements.txt
file that was used to generate that zip file alongside the zip in same folder.