使用Zappa将Django应用实例化为lambda函数时,出现以下错误。
[1549659279288] Instancing..
[1549659279532] cannot import name 'models': 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 9, in get_django_wsgi
from django.core.wsgi import get_wsgi_application
File "/var/task/django/core/wsgi.py", line 2, in <module>
from django.core.handlers.wsgi import WSGIHandler
File "/var/task/django/core/handlers/wsgi.py", line 8, in <module>
from django.core.handlers import base
File "/var/task/django/core/handlers/base.py", line 7, in <module>
from django.urls import get_resolver, set_urlconf
File "/var/task/django/urls/__init__.py", line 1, in <module>
from .base import (
File "/var/task/django/urls/base.py", line 8, in <module>
from .exceptions import NoReverseMatch, Resolver404
File "/var/task/django/urls/exceptions.py", line 1, in <module>
from django.http import Http404
File "/var/task/django/http/__init__.py", line 5, in <module>
from django.http.response import (
File "/var/task/django/http/response.py", line 13, in <module>
from django.core.serializers.json import DjangoJSONEncoder
File "/var/task/django/core/serializers/__init__.py", line 23, in <module>
from django.core.serializers.base import SerializerDoesNotExist
File "/var/task/django/core/serializers/base.py", line 6, in <module>
from django.db import models
ImportError: cannot import name 'models'
我尝试使用在本地运行应用程序
python manage.py runserver
,并且在本地运行良好。 但是,将应用程序部署到lambda函数时,出现上述错误。
我正在使用Django 2.0.10,Python 3.6和AWS Aurora RDS。
我希望lambda函数实例不会出错,就像在本地一样。
答案 0 :(得分:0)
在部署后调用zappa以保留打包的zip,并检查文件夹结构或尝试从该文件夹运行项目。
您是否将Django添加到需求文件中?我记得Zappa从全新的虚拟环境重建了lambda软件包,安装了requirements.txt并应用了您的文件夹。
或仔细检查cloudwatch日志中是否存在导入错误。仅在部署后刷新容器时才会显示导入错误,而导入错误不会在每次lambda调用时都显示。