简体   繁体   English

使用 CLI 将 flask 应用程序部署到弹性 beanstalk 时出现 502 错误

[英]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:我试过了:

  • Accessing the application using both the URL from the console, and also eb open .从控制台使用 URL 和eb open访问应用程序。
  • Specifying the port 5000 (default flask) and 8000 at the end of the URL.在 URL 的末尾指定端口 5000(默认烧瓶)和 8000。
  • Using 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.

相关问题 将带有熊猫的Flask应用程序部署到Elastic Beanstalk - Deploying Flask Application with pandas to Elastic Beanstalk 将 Django 应用程序部署到 Elastic Beanstalk AWS 502 错误网关 - Deploying a Django application to Elastic Beanstalk AWS 502 Bad Gateway 使用 Elastic Beanstalk 部署 Flask 应用程序时遇到问题 - Trouble deploying Flask app using Elastic Beanstalk 在Elastic Beanstalk上使用Docker部署Flask应用程序:资源创建取消错误 - Deploying Flask app with Docker on Elastic Beanstalk: resource creation cancelled error 将 Django 应用程序部署到 Elastic Beanstalk 时出现内部服务器错误 500 - Internal Server Error 500 when deploying Django Application to Elastic Beanstalk Elastic Beanstalk Flask应用程序上的HTTPS - HTTPS on Elastic Beanstalk Flask application 在 AWS Elastic Beanstalk 中部署 Flask 应用程序 - Deploying Flask App in AWS Elastic Beanstalk 部署 Flask 应用程序时,AWS ElasticBeanstalk 中出现 502 Bad Gateway 错误 - 502 Bad Gateway Error in AWS ElasticBeanstalk while deploying Flask Application 如何使用应用程序工厂将Flask应用程序部署到AWS Elastic beantalk - How to deploy Flask app to AWS Elastic beanstalk using an application factory 使用 awsebcli 部署 Elastic Beanstalk 应用程序时出现“操作被拒绝”错误 - 'Operation Denied' Error when deploying an Elastic Beanstalk app using awsebcli
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM