Connecting to web app running on localhost on an Amazon EC2 from another computer
Solution 1
You need to tell the Flask Dev webserver to run on 0.0.0.0
instead of localhost
.
You specify this option when calling the .run()
function:
app.run(host='0.0.0.0', debug=True, port=5000)
If you then send a request to the Public IP of your EC2 instance on port 5000 you will reach your Flask Dev webserver.
eg: http://EC2_IP:5000/
Hope this helps :)
Solution 2
You cannot connect to localhost on a remote machine without a proxy. If you want to test it you will need to change the binding to the public IP address or 0.0.0.0
.
You will then have to lock down access to your own IP address through the security settings in AWS.
cauchy_cat
Updated on June 28, 2022Comments
-
cauchy_cat almost 2 years
currently I am working on a web app development and I am running my server on an Amazon ec2 instance. I am testing my (web app which uses Flask) by running the server on localhost:5000 as usual. However I don't have access to the gui hence I don't see my app and test it like I would do on a browser. I have a Mac OS X computer so my question is how can I see the localhost of Amazon EC2 from my mac's browser ?
-
user391339 over 4 yearsyou likely need to create a security group setting and then apply it to the ec2 instance for this to work. also if you are running this from the terminal, type flask run --help to get acquainted or flask run -h 0.0.0.0 -p 5000