Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda : How to use Pillow library?

I'm trying to create an AWS lambda function in order to create thumbnail of my uploaded images. My script is running well locally, I followed this tutorial to deploy my function but I have a problem with the Pillow library, indeed when I'm testing my function I can see this following log :

enter image description here

I found this post with the same issue but in my case I can't execute command line on the machine.

like image 724
Matthieu DELMAIRE Avatar asked Jun 23 '16 09:06

Matthieu DELMAIRE


1 Answers

You must include the libjpeg.so in your lambda package, but it will also require some tweaking with the patchelf utility. Assuming that you prepare the lambda package via "pip install module-name -t" (rather than via virtualenv), do the following:

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 it can be 'apt install'ed, but under other Linuxes it may need to be built from source.

like image 118
Leon Avatar answered Nov 19 '22 07:11

Leon