Skip to content

Instantly share code, notes, and snippets.

@akx
Last active March 6, 2020 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akx/b0af7a9c7a0e46792556f1c0e24f796b to your computer and use it in GitHub Desktop.
Save akx/b0af7a9c7a0e46792556f1c0e24f796b to your computer and use it in GitHub Desktop.
Super simple flask thing
import os
from flask import *
app = Flask(__name__)
@app.route("/calculate/<a>/<b>")
def calculate(a, b):
result = int(a) ** int(b)
return str(result)
if __name__ == '__main__':
app.run(debug=True, host="0", port="9999")

Developing/debugging a Flask app

  • Set up a virtualenv
  • pip install flask
  • add calc_server.py
  • debug/run with python calc_server.py (autoreloading, debugging, etc.)
  • Access e.g. http://localhost:9999/calculate/9652/343

Running in production in an EC2 box

  • Set up a virtualenv
  • pip install flask gunicorn
  • Run in production mode with gunicorn --bind=0:9999 calc_server:app
  • Ensure port 9999 (or whatever you choose) is open to the world in the EC2 security group
  • Access e.g. http://ec2-instance-ip-here:9999/calculate/9652/343

Keeping the app up and running at all times

  • Set up a systemd unit file for Gunicorn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment