Zappa正确设置了“ app_function”

时间:2018-07-23 07:52:18

标签: python flask zappa

我的Flask应用程序具有以下设置:

├── app
│   ├── __init__.py
│   └── routes.py
├── application.py
└── zappa_settings.json

application.py

import os
from app import config_app


if __name__ == "__main__":
    application = config_app(os.environ, __name__)
    application.run(threaded=True)

app/__init__.py

from flask import Flask

def config_app(config, name=__name__):
    app = Flask(__name__)
    app.config.from_mapping(config)
    ...
    return app

现在,我正在尝试将具有zappa的应用程序部署到AWS。运行zappa init时,会提示您输入app_function,但是我不完全确定将其设置为什么。到目前为止,我已经尝试过

"app_function": "application.application"

最后返回一个502错误。

运行zappa tail

Traceback (most recent call last):
  File "/var/task/handler.py", line 567, in lambda_handler
  return LambdaHandler.lambda_handler(event, context)
  File "/var/task/handler.py", line 237, in lambda_handler
  handler = cls()
  File "/var/task/handler.py", line 132, in __init__
  wsgi_app_function = getattr(self.app_module, self.settings.APP_FUNCTION)
AttributeError: module 'application' has no attribute 'application'

1 个答案:

答案 0 :(得分:0)

显然,这是application.py的正确格式:

application = config_app(os.environ, __name__)

if __name__ == "__main__":
     application.run(threaded=True)