Background
I have been struggling for the past few days to deploy a Lambda that uses Pillow, and I am deploying using Python 3.6. It may be noteworthy a
Basically, you have to compile the libraries (eg, PIL) either using Docker or, even better, an EC2 instance.
Launch an Docker container like this: docker run --rm -it -v "%cd%:/code" lambci/lambda:build-python3.6 sh
Inside there, navigate to the /code dir (cd /code
), create a virtualenv (virtualenv env
), activate it (source env/bin/activate
) and finally, install your library (pip install pillow
).
Once you have installed your library, you can exit the container. The secret here is to move your package library to the root folder (where your main .py file is). For example, move the folder env/lib/python3.6/site-packages/PIL
to the root.
Then, zip your PIL folder together with your .py file and you're set!
I just did it and documented it in full here: https://learn-serverless.org/post/deploying-pillow-aws-lambda/