We are building for Python 3.8 and on the latest amazonlinux 2. You can either use lambda.zip directly or add lambda-layer.zip as a layer to your lambda_function.py. Python binary is in /opt/bin/python3.8.
- Logging in to EC2 and creating a deployment package by hand is clumsy. Instead, script package creation around the
amazonlinux 2image.
- Mount
/srcas a docker volume, this is where you should put your lambda code. - Deployment packages
lambda.zipandlambda-layer.zipare written to/deploydirectory. - Modify and mount
run.shscript to/opt/run.sh. - Pass environment variables:
GIT_REPO- clone this git repo into/src.PIP_PACKAGES- space separated list of packages you want to add to your lambda zip.REM_LAMBDA_FILE- (OPTIONAL) remove the originallambda_function.pyfile fromlambda-layer.zipif you don't need it there.
$ docker pull sam2kb/lambda
$ docker run --rm \
-v "$(pwd)/src:/src" \
-v "$(pwd)/run.sh:/opt/run.sh" \
-v "$(pwd)/deploy:/deploy" \
-e GIT_REPO="https://github.com/some/repo" \
-e PIP_PACKAGES="cryptography imap_tools " \
-e REM_LAMBDA_FILE="lambda_function.py" \
sam2kb/lambda \
bash /opt/run.shRemember to modify docker-compose.yml file first
$ docker-compose run --rm lambda
Modify run.sh to suit your own purposes
Pass a build ARG with any other Python version as such PYTHON_VER=3.8.0
$ docker build --build-arg PYTHON_VER=3.8.0 -t mylambda .Or with docker-compose
$ docker-compose build --build-arg PYTHON_VER=3.8.0