ddd
ddd

Reputation: 5029

Why can't I hit Flask app when port 5000 is open for inbound traffic on EC2

I am trying to deploy my Flask app on EC2. Instead of using Beanstalk, I want to deploy it manually. The ultimate goal is to set up wsgi with nginx. Before doing that, I just want to deploy it like what I did on the local dev computer, i.e. start virtualenv, install all the dependencies, and run python3 application.py. By default it runs on port 5000. It works locally at "localhost:5000/api". (api is the blueprint url). However, when I do the same on EC2 (ubuntu) instance, it does not work. I put the url "ec2-public-ip:5000/api" in the browser, it says "This page isn't working. [ip] didn't send any data".

application.py is the entry point of the app:

from myapp.api.factory import create_app

app = create_app(True)

def main():
    app.run(debug=True, threaded=True)

if __name__ == "__main__":
    main()

I set up the security group for this instance which allows inbound traffic from anywhere (0.0.0.0/0) for port 80, 22, 5000

enter image description here

Why does it not work when accessing from 5000?

Upvotes: 2

Views: 7311

Answers (1)

BeeBee8
BeeBee8

Reputation: 3074

Add this

app.run(host= '0.0.0.0')

As per docs

http://flask.pocoo.org/docs/1.0/quickstart/#a-minimal-application

Externally Visible Server If you run the server you will notice that the server is only accessible from your own computer, not from any other in the network. This is the default because in debugging mode a user of the application can execute arbitrary Python code on your computer.

If you have the debugger disabled or trust the users on your network, you can make the server publicly available simply by adding --host=0.0.0.0 to the command line:

flask run --host=0.0.0.0 This tells your operating system to listen on all public IPs.

Upvotes: 7

Related Questions