1

I can't preview this appliation using AWS Cloud9 (c9) python flask:

from flask import Flask
import os
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

host = 'localhost' # '0.0.0.0' #"127.0.0.1" # I tried all of these ip's

if __name__ == '__main__':
    app.debug = True
    port = int(os.environ.get("PORT", 8080)) # I also tried port was 5000
    app.run(host=host, port=port)

# This is the error I got 52.15.73.96 The connection has timed out
#The server at 52.15.73.96 is taking too long to respond.

This is similar to AWS cloud9 timeout when running flask application

hlindwin
  • 81
  • 1
  • 7

3 Answers3

3

Here is the answer: You have to get past the AWS firewall. You have to

  1. Go into EC2 (from the list of all AWS services)
  2. Click security groups
  3. Click your Cloud9 instance
  4. Click Inbound
  5. Click Edit
  6. Click Add Rule
  7. Add this rule:

    • For Type, choose Custom TCP Rule. - All Traffic also worked.
    • For Port Range, type 8080, 8081, or 8082. - If you did 'All Traffic' this will default to all ports.
    • For Source, choose Anywhere, which looks like 0.0.0.0/0

    Here is a screen shot link: https://i.stack.imgur.com/xpW5F.jpg

AWS does have this, buried, in their C9 documentation. https://docs.aws.amazon.com/cloud9/latest/user-guide/app-preview.html#app-preview-share-security-group In Share a Running Application over the Internet, Step 2: Set Up the Security Group for the Instance

hlindwin
  • 81
  • 1
  • 7
1

You need to run your server in 0.0.0.0 using port 8080 (or other available C9 ports).

Change your app.run() command to something like this:

app.run(host='0.0.0.0', port=8080, debug=True)

If 8080 doesn’t work, try with 80.

Tushar Niras
  • 3,654
  • 2
  • 22
  • 24
  • I believe those app.run's are the same as mine. I tried port 80 with ip 0.0.0.0 and got a permission's denied error. – hlindwin Apr 16 '18 at 19:00
  • I fixed that issue with running python with sudo, but I still had the timing out until I changed the AWS EC2 security settings to allow incoming IP's: an inbound rule add – hlindwin Apr 17 '18 at 19:29
0
flask run --host=127.0.0.1 --port=8080