[英]502 error deploying flask application to elastic beanstalk using CLI
Running into an issue with deploying a very straight-forward Hello, World type flask application to AWS Elastic Beanstalk.在将非常简单的 Hello, World 类型 flask 应用程序部署到 AWS Elastic Beanstalk 时遇到问题。 I'm using the eb CLI tool, installed on Mac with brew and python 3. Some sample code below:
我正在使用 eb CLI 工具,安装在 Mac 上,带有 brew 和 python 3。下面的一些示例代码:
from flask import Flask
app = 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)
It runs locally as expected, and I can deploy it through the CLI, but when I go to access the application I'm getting a 502 Bad Gateway.它按预期在本地运行,我可以通过 CLI 部署它,但是当我 go 访问应用程序时,我得到一个 502 Bad Gateway。
I've tried:我试过了:
eb open
.eb open
访问应用程序。app.run()
, and app.run(port=8000)
with no success.app.run()
和app.run(port=8000)
没有成功。 I've had a look through the documentation but couldn't find a fix.我浏览了文档,但找不到修复程序。 If folks have any suggestions or links they think would be helpful that'd be appreciated.
如果人们有任何他们认为会有所帮助的建议或链接,我们将不胜感激。
Your application should be called application
not app
.您的应用程序应称为
application
而不是app
。
Below is the corrected application.py
file.下面是更正后的
application.py
文件。 I verified that it works using Python 3.7 running on 64bit Amazon Linux 2/3.1.0
platform:我验证它使用
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.