Running into an issue with deploying a very straight-forward Hello, World type flask application to AWS Elastic Beanstalk. I'm using the eb CLI tool, installed on Mac with brew and python 3. Some sample code below:
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.
I've tried:
eb open
.app.run()
, and app.run(port=8000)
with no success.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
.
Below is the corrected application.py
file. I verified that it works using Python 3.7 running on 64bit Amazon Linux 2/3.1.0
platform:
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.