Can't preview in aws c9



Hi, I made a new c9 account with AWS. I tried to run a simple application. It works with my pre-AWS c9 account, but not with an AWS c9 account. How can I get this to work?

Installed flask in a virtual environment first. The commands are:

$virtualenv venv
$. venv/bin/activate
$pip install flask 

Here is the - the simplest flask app to run on c9
from flask import Flask
import os
app = Flask(name)

def hello():
    return "Hello World!"

if __name__ == '__main__':
    app.debug = True
    port = int(os.environ.get("PORT", 5000))'', port=port)


If you’re using AWS Cloud9’s preview URL, you’ll need to run your code on rather than


Hi Bryceito,
Can you be more specific? I’ve tried a few different ways of adding the port/IP

#VERSION 1    
# if __name__ == '__main__':
#'IP', ''), port=int(os.getenv('PORT', 8080)))
#     app.debug(True)

# if __name__ == '__main__':
#     app.debug = True
#['IP'], port=os.environ['PORT']) 
#os.environ['IP'] is
#os.environ['PORT'] is  8080


if __name__ == '__main__':
    app.debug = True
    host = 'localhost' # '' #"" # I tried all of these ips
    port = int(os.environ.get("PORT", 8080)), port=port)

For Version 1, 2 and 3, I get directed to which doesn’t load: ERR_CONNECTION_REFUSED

For Version 3
host = ‘localhost’ at least points me to a url that might be trying to load:, but then fails with ERR_CONNECTION_TIMED_OUT

I am running these with the Green Run GUI button, not in the c9 terminal.



NVM, I figured it out - I wasn’t running/previewing the app correctly.

Running the App

To run the app, go to the terminal and type

Previewing the App

To view the app, go to Preview in C9 toolbar and click Preview Running App. You’ll be directed to a crazy url. Mine was (edited a little)

Code in

import os
from flask import Flask

app = Flask(__name__)

def hello():
    return "Let's double check"

if __name__ == '__main__':
    app.debug = True['IP'], port=os.environ['PORT'])


There are two different URLs for workspaces: the private URL (the one that is currently working for you) and the public one (the IP address from the Share panel, which corresponds directly to your machine). You can use the public IP address as your Preview URL, but you will need to open up access to your host. You can find some documentation on how to do that here:

Hope this helps!