johni
johni

Reputation: 5568

AWS Lambda Python package - no module named redis

I have a python package that I would like to upload to AWS Lambda. The package works on two different machines with no dependencies issues at all.

However, when uploading the same folder to AWS Lambda, I get the following error:

Unable to import module 'tweet_analyzer_python/lambda_handler': No module named redis

Here is a list of the files in the package:

.
|-- event.json
|-- lambda_handler.py
|-- redis
|   |-- client.py
|   |-- client.pyc
|   |-- _compat.py
|   |-- _compat.pyc
|   |-- connection.py
|   |-- connection.pyc
|   |-- exceptions.py
|   |-- exceptions.pyc
|   |-- __init__.py
|   |-- __init__.pyc
|   |-- lock.py
|   |-- lock.pyc
|   |-- sentinel.py
|   |-- utils.py
|   `-- utils.pyc
|-- redis-2.10.5-py2.7.egg-info
|   |-- dependency_links.txt
|   |-- installed-files.txt
|   |-- PKG-INFO
|   |-- SOURCES.txt
|   `-- top_level.txt
|-- retrying-1.3.3-py2.7.egg-info
|   |-- dependency_links.txt
|   |-- installed-files.txt
|   |-- PKG-INFO
|   |-- requires.txt
|   |-- SOURCES.txt
|   `-- top_level.txt
|-- retrying.py
|-- retrying.pyc
|-- six-1.10.0-py2.7.egg-info
|   |-- dependency_links.txt
|   |-- installed-files.txt
|   |-- PKG-INFO
|   |-- SOURCES.txt
|   `-- top_level.txt
|-- six.py
`-- six.pyc

For double-checking, I have downloaded the same zip file that was uploaded to AWS Lambda and put it on a clean linux machine. When running:

python tweet_analyzer_python/lambda_handler

I had no issues at all.

Can someone explain me what am I doing wrong?

Thanks!

Upvotes: 1

Views: 4502

Answers (1)

apoclyps
apoclyps

Reputation: 531

When you run 'lambda_handler.py' locally you are running a main methods within the python file. The lambda function however calls the lambda_handler method within lambda_handler.py directly.

Your lambda handler is not configured to run 'lambda_handler.lambda_handler' and is failing on 'tweet_analyzer_python/lambda_handler'

Either :

  • 1) rename lambda_handler.py to tweet_analyzer_python or
  • 2) change your lambda handler to 'lambda_handler.lambda_handler'

To change your handler; go your lambda in AWS, select configuration, and update the handler and save the function.

Also ensure your redis dep is packaged in your zipped lambda function.

Upvotes: 1

Related Questions