尝试使用Flask构建简单的zappa应用程序,但zappa deploy dev
后出现以下错误:
错误:警告!对已部署的 lambda 的状态检查失败。对"/"的 GET 请求生成了 502 响应代码。
▼ 结构
.
├── app
│ ├── env
│ └── main.py
└── zappa_settings.json
▼ 应用程序/主.py
#main.py
import sys
from flask import Flask, redirect, request, jsonify, url_for, render_template
app = Flask(__name__)
@app.route('/', methods=['GET'])
def index():
return 'hello zappa!'
if __name__ == '__main__':
if len(sys.argv) > 1:
app.debug = True
app.jinja_env.auto_reload = True
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.run(host='0.0.0.0', port=4000)
else:
app.run(host='0.0.0.0')
▼ zappa_settings.json
{
"dev": {
"app_function": "app.main",
"profile_name": null,
"project_name": "app",
"runtime": "python3.8",
"s3_bucket": "zappa-kgikw9e6r"
}
}
▼扎帕尾巴
[1644312001414] [ERROR] TypeError: the 'package' argument is required to perform a relative import for '.app'
Traceback (most recent call last):
File "/var/task/handler.py", line 657, in lambda_handler
return LambdaHandler.lambda_handler(event, context)
File "/var/task/handler.py", line 251, in lambda_handler
handler = cls()
File "/var/task/handler.py", line 148, in __init__
self.app_module = importlib.import_module(self.settings.APP_MODULE)
File "/var/lang/lib/python3.8/importlib/__init__.py", line 122, in import_module
raise TypeError(msg.format(name))
- 使用的扎帕版本:0.54.1
- Ubuntu 20.04, Python 3.8
有人来帮忙吗?
尝试使用这个希望这对你有用,虽然我以前没有使用过 zappa,但我没有看到你的配置文件有任何问题。
#main.py
import sys
from flask import Flask, redirect, request, jsonify, url_for, render_template
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
@app.route('/', methods=['GET'])
def index():
return 'hello zappa!'
if __name__ == '__main__':
if len(sys.argv) > 1:
app.run(host='0.0.0.0', port=4000, debug='True')
else:
app.run(host='0.0.0.0')