3

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?

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

After some research, there is a library you need to add to requirements.txt file: setuptools

After that, no problems!

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.