0
votes

I'm trying to deploy a simple service to AWS Lambda (on Python 3.6) that requires PIL. I'm using the serverless framework, so to start I simply did pip3 freeze > requirements.txt on an ec2 instance with my code and all of the dependencies installed, and when I called the Lambda function I got the following error (from CloudWatch logs):

Unable to import module 'lambda_function': No module named 'PIL'

I then tried to install & package pillow manually by doing pip3 install pillow -t .vendor and added the following to my serverless.yml:

package: include: - .vendor/**

But I'm still getting the same error. Am I doing something wrong?

EDIT: It seems that not using the serverless architecture and instead packaging the dependencies myself fixed the issue. Why is this?

1

1 Answers

0
votes

This is because pillow is not a standard python library found in AWS Lambda environment by default. To include and use it in your code you need to make a custom deployment package with all your dependicies and your code included and then deploy it.

And this is what you did to make it run.