Reputation: 1618
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?
Upvotes: 2
Views: 2730
Reputation: 2099
I expect many people finding this page after upgrading to Python 3.12, as setuptools is not included be default anymore.
The solution is simply to add setuptools as dependency.
What happens with pkg_resources also applies to distutils.
Upvotes: 0
Reputation: 471
After some research, there is a library you need to add to requirements.txt file: setuptools
After that, no problems!
Upvotes: 1
Reputation: 2863
I found this useful link which lists out all python modules installed in lambda execution environment. Though this link list out for Python 2.7, you can refer this for Python 3.6 as well. If a module you need is not present in this list, you can package it with the ZIP file.
AWS doc also mentions list of available libraries for lambda execution env, but it just mentions Boto3
package and doesn't explicitly list out the modules/dependent modules along with it.
Upvotes: 1
Reputation: 3081
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.
Upvotes: 3