Build and Deploy a Python Web App to Amazon in 30 Mins


Published on

Presented at Klab.Rw tech and entrpreneurA few slides and associated code on how to Build and Deploy a Python Web Application in under 30 minutes.

Published in: Technology

Build and Deploy a Python Web App to Amazon in 30 Mins

  1. 1. Build and Deploy a WebApplication in 30 Minutes August 23rd, 2012 @kLab Kigali, Rwanda Jeff Hull @jsh2134
  2. 2. In 30 Minutes we will● Create an App● Deploy a Server● Launch the App Pro Tip: You can fork the finished code here
  3. 3. Who Are You?● Buzzient Social CRM and Analytics – Dev Manager and Lead Engineer – 100K Lines of Code, 15 Servers, 24/7 Ops – Recruited and Managed team of 4+ Engineers● My Ivy Leaguer Test Prep and Tutoring Service – Co-Founder and Lead Developer – Built Tutor/Client CRM software● Web Analytics – Software Developer Intern – Built Ad Scraper that powered their Ad Impact product
  4. 4. No Really, Who Are You?● I like to Build things (on the Internet)● The Internet is perfect – For Creation – For Distribution – For Disruption – For Monetization – For Success – For Failure – For LOLcats●
  5. 5. “Startups are like jumpingout of a plane and figuring out how to build the parachute as you fall.” -- Someone Smart
  6. 6. Learn by ExperienceWrite Code ● So you can learn how good/bad it isShare Code ● So someone can tell you how good/bad it isDeploy Code ● So the user can show you how good/bad it is
  7. 7. Best Advice: Just Dive In● Social Coding – GitHub – StackOverflow● Courses – –● Hacker News – – Code Tutorials, Startup News, Rants and Raves
  8. 8. The App● Pure Python● A Simple Flask App● Displays Facebook Images matching a word● Use Twitter Bootstrap for Style● Use Git for Version Control● Deploy to Amazon Lets get started...
  9. 9. Friends dont let Friends not use Git ● Git is your friend ● GitHub is your best friendMore Octocats at
  10. 10. Lets “git” started$ curl -u jsh2134 -d{"name":"my_repo"}$ git init my_repo$ cd my_repo$ git remote add origin$ vim README$ git add README$ git commit -m first commit$ git push origin
  11. 11. What is Flask?● Lightweight Python web Framework● Like Django but Simpler – Uses all the best parts● ~5000 Lines of Code – Can easily dig in if you need to debug or change● Leverages Jinja and Werkzeug – Werkzeug debugger is incredible
  12. 12. The Simplest Flask Appfrom flask import Flaskapp = Flask(__name__)@app.route(/)def hello_world(): return Hello World!if __name__ == __main__:
  13. 13. And Now Some Flask Code
  14. 14. Jinja Templates● Separate the Python from the HTML● Add Logic to your HTML● Simple Syntax● Template Inheritance● Less gray hairs
  15. 15. Pause for Some Jinja Code
  16. 16. Boto● Python interface to Amazon Web Services● Create/Start/Stop Servers on Demand – Can do everything actually – Boto is @&$?ing awesome● Actively Developed● AWS very Flexible
  17. 17. A Quick Boto Break
  18. 18. Fabric● Execute commands on remote server● Installation Scripts● Update Code● System Admin Tasks● We will use Fabric to deploy our app
  19. 19. Fabric Examples
  20. 20. The Final Code Base requirements.txt templates/photos.htmlstatic/css/bootstrap.css
  21. 21. Deploy the Code
  22. 22. Finito● Fork this on Github –● Contact – @jsh2134 – –● Slides will be posted online shortly