pythonamazon-web-serviceslambdaaws-lambda

AWS Lambda + Python - No module named pkg_resources


I am trying to create a python deployment package for AWS Lambda. I have followed documentation specified at Creating a Deployment Package (Python)

While testing created Lambda function, I am getting following error:

No module named pkg_resources

On debugging, identified that pint package requires this pkg_resources. AFAIK, pkg_resources will be created during Python distro installation.

I am assuming since Python is already available on Lambda server, it should also have the pkg_resources.

What am I missing here? Can someone please help?


Solution

  • A good way to make sure that all the packages are available to you is installing all the dependencies in the AWS AMI. It offers the same environment as lambda at bootstrap. This way you will be able to find out which packages are missing from the AWS AMI python and python installed on your system. You might want to look at frameworks like serverless which have plugins like serverless-python-requirements which can build packages for you. I usually create a venv and check everything is working. Here is link which shows you how to do that.