Miserlou / Zappa

Serverless Python
https://blog.zappa.io/
MIT License
11.88k stars 1.2k forks source link

zappa deploy fails with import error even though the module is present in the package #1687

Open wholeinsoul opened 6 years ago

wholeinsoul commented 6 years ago

Context

I have django project that works locally and in elasticbeanstalk. Now I'm trying to deploy it to AWS lambda using zappa. But I'm getting the following error even though the module urllib3 is present in the package zip.

No module named urllib3: ImportError
Traceback (most recent call last):
  File "/var/task/handler.py", line 580, in lambda_handler
  return LambdaHandler.lambda_handler(event, context)
  File "/var/task/handler.py", line 245, in lambda_handler
  handler = cls()
  File "/var/task/handler.py", line 151, in __init__
  wsgi_app_function = get_django_wsgi(self.settings.DJANGO_SETTINGS)
  File "/var/task/zappa/ext/django_zappa.py", line 20, in get_django_wsgi
  return get_wsgi_application()
  File "/tmp/task/django/core/wsgi.py", line 14, in get_wsgi_application
  django.setup()
  File "/tmp/task/django/__init__.py", line 17, in setup
  configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/tmp/task/django/conf/__init__.py", line 48, in __getattr__
  self._setup(name)
  File "/tmp/task/django/conf/__init__.py", line 44, in _setup
  self._wrapped = Settings(settings_module)
  File "/tmp/task/django/conf/__init__.py", line 92, in __init__
  mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
  __import__(name)
  File "/var/task/api/settings/test.py", line 4, in <module>
  File "/tmp/task/elasticsearch/__init__.py", line 17, in <module>
  from .client import Elasticsearch
  File "/tmp/task/elasticsearch/client/__init__.py", line 5, in <module>
  from ..transport import Transport
  File "/tmp/task/elasticsearch/transport.py", line 5, in <module>
  from .connection import Urllib3HttpConnection
  File "/tmp/task/elasticsearch/connection/__init__.py", line 3, in <module>
  from .http_urllib3 import Urllib3HttpConnection
  File "/tmp/task/elasticsearch/connection/http_urllib3.py", line 2, in <module>
  import urllib3

My project directory structure is:

/api --> this has all my django apps and code /manage.py /zappa_settings.json Environment zappa: 0.47.0 docker image built using https://github.com/danielwhatmuff/zappa python 2.7 venv)bash-4.2# pip freeze | grep url urllib3==1.20 zappa_settings.json: ``` { "dev": { "django_settings": "api.settings.test", "profile_name": null, "project_name": "server", "runtime": "python2.7", "s3_bucket": "zappa-server-localhost", "slim_handler": true, "exclude": [ "*.mp4", "*.ogv", "*.webm", "logs", "*.log", "media", "static_dirs", ".git", ".elasticbeanstalk", ".ropeproject" ], "environment_variables": { //removed } }, } ```
ccdesales commented 5 years ago

I had a similar issue, which persisted until I realised my Lambda environment was running on Python 3.6, while my local running Zappa was 2.7.

Abishek05 commented 5 years ago

Is this issue fixed?