AWS Lambda: How to use the pillow library?

I am trying to create an AWS lambda function to sketch my uploaded images. My script works well locally, I followed this tutorial to deploy my function, but I have a problem with the Pillow library, really when I test my function. I see the following log:

enter image description here

I found this post with the same problem, but in my case I cannot execute the command line on the machine.

+6
source share
1 answer

You must include libjpeg.so in your lambda package, but it will also require some configuration using the patchelf utility. Assuming you are preparing a lambda package through " pip install module-name -t " (and not through virtualenv ), follow these steps:

 cd into/your/local/lambda/package/dir cp -L $(ldd PIL/_imaging.so|grep libjpeg|awk '{print $3}') PIL/ patchelf --set-rpath PIL PIL/_imaging.so # zip, deploy and test the package 

This script works for Pillow version 3.2.0.

Regarding patchelf : under Ubuntu there may be 'apt install' ed, but under other Linuxes it may be necessary to build from the source .

+5
source

All Articles