將非常簡單的 Hello, World 類型的燒瓶應用程序部署到 AWS Elastic Beanstalk 時遇到問題。我正在使用 eb CLI 工具,它在 Mac 上安裝了 brew 和 python 3。下面是一些示例代碼:from flask import Flaskapp = Flask(__name__)@app.route('/')def hello_world(): return 'Hello, World!'@app.route('/<username>')def hello_user(username): return f'Hello, {username}!'# run the app.if __name__ == "__main__": # Setting debug to True enables debug output. This line should be # removed before deploying a production app. app.debug = True app.run(port=8000)它按預期在本地運行,我可以通過 CLI 部署它,但是當我訪問該應用程序時,我收到 502 Bad Gateway。我試過了:使用來自控制臺的 URL 和eb open.在 URL 末尾指定端口 5000(默認 flask)和 8000。使用app.run(),但app.run(port=8000)沒有成功。我瀏覽了文檔,但找不到修復方法。如果人們有任何他們認為有用的建議或鏈接,我們將不勝感激。
1 回答

qq_笑_17
TA貢獻1818條經驗 獲得超7個贊
您的應用程序應稱為applicationnot app。
下面是更正后的application.py文件。我驗證了它可以使用Python 3.7 running on 64bit Amazon Linux 2/3.1.0平臺工作:
from flask import Flask
application = Flask(__name__)
@application.route('/')
def hello_world():
return 'Hello, World!'
@application.route('/<username>')
def hello_user(username):
return f'Hello, {username}!'
# run the app.
if __name__ == "__main__":
# Setting debug to True enables debug output. This line should be
# removed before deploying a production app.
application.debug = True
application.run(port=8000)
添加回答
舉報
0/150
提交
取消