0
votes

I am trying to use the Pillow Image in my project, passing it as a local library to my AWS Lambda Function use.

The files are located like this:

Backend(folder with the lambda_handler code)

Libraries(folder with some folders to store some libraries)

PIL(folder with the files inside Libraries)

My lambda_handler code is importing Image like this:

from Libraries.PIL import Image

The only time that I use Image is to open one Image as an argument to one function.

When I upload and test the Lambda Function, I am receiving the following error:

{
    "errorMessage": "Unable to import module 'Backend/lambda_function': cannot import name '_imaging' from 'Libraries.PIL' (/var/task/Libraries/PIL/__init__.py)",
    "errorType": "Runtime.ImportModuleError"
}

I already uninstall all Pillow versions and tried using only one version, the most recent version (7.2.0), and some old versions (6.0.0 and 5.0.0).

I am using Python 3.7

Note: Running the program locally everything works ok, but when I run it in AWS Lambda the I receive the error.

1

1 Answers

1
votes

The easiest way to use Pillow, which also could solve your issue, is through Lambda layers.

A popular repository with such layers (including pillow) is keithrozario / Klayers on github. To use it, you would locate ARN of the layer based on your region. The list of the ARNs for python 3.7 is here.

For example, for us-east-1 the layer added would be:

enter image description here

And in your function you would use it as follow e.g.:

from PIL import Image