8/03/2021

make python package zip for lambda layer using docker

 Here is good reference for this subject:

https://aws.amazon.com/premiumsupport/knowledge-center/lambda-layer-simulated-docker/

https://dev.to/matthewvielkind/creating-python-aws-lambda-layers-with-docker-4376



If we use docker then it's very simple.

Let's go through step by step


1. make Main folder & python library folder

ex) In this tutorial, we suppose to need flask package

mkdir flask-layer
cd flask-layer
mkdir -pv python/lib/python3.6/site-packages
or
mkdir -pv python/lib/python3.8/site-packages


2. make requirements.txt and put packages to install by pip

flask==1.1.1


So folder structure looks like this:

├── requirements.txt └── python/ └── lib/ ├── python3.6/ │ └── site-packages/ └── python3.8/ └── site-packages/


3. Run docker to install packages

note, change python version properly

docker run -v "$PWD":/var/task "public.ecr.aws/sam/build-python3.6" /bin/sh -c "pip install -r requirements.txt -t python/lib/python3.6/site-packages/; exit"

 

4. compress package to zip

zip -r yourpack.zip python > /dev/null


5. use zip file for your lambda

That's it all.


Thank you.

www.marearts.com

๐Ÿ™‡๐Ÿป‍♂️


No comments:

Post a Comment