SlideShare a Scribd company logo
lanyrd.com/sdmbmk
Heroku 101
!
dgouldin@heroku.com
@dgouldin
lanyrd.com/sdmbmk
What is Heroku?
The application platform
lanyrd.com/sdmbmk
You write your app.
We do the rest.
lanyrd.com/sdmbmk
LOW HIGH
SCALE
drag to scale
lanyrd.com/sdmbmk
5 Billion
requests per day
3+ Million
Apps Created
125+
Add-on services
lanyrd.com/sdmbmk
What’s a Heroku app?
lanyrd.com/sdmbmk
The Twelve-Factor app
12factor.net
lanyrd.com/sdmbmk
Let’s dive in!
lanyrd.com/sdmbmk
Assumptions
You want to learn about Heroku.
You know (a bit) of Python.
You have Python, pip, and virtualenv*.
lanyrd.com/sdmbmk
*install.python-guide.org
lanyrd.com/sdmbmk
Install the Toolbelt
toolbelt.heroku.com
lanyrd.com/sdmbmk
$ heroku login
Log in
lanyrd.com/sdmbmk
X. Dev/prod parity
12factor.net/dev-prod-parity
lanyrd.com/sdmbmk
Create a Flask app
devcenter.heroku.com/articles/getting-started-with-python
lanyrd.com/sdmbmk
$ mkdir hello-heroku
$ cd hello-heroku
$ virtualenv venv
$ source venv/bin/activate
$ pip install Flask gunicorn
Create a vitualenv and install requirements
lanyrd.com/sdmbmk
import os
from flask import Flask
!
app = Flask(__name__)
!
@app.route('/')
def hello():
return 'Hello World!'
hello.py
lanyrd.com/sdmbmk
web: gunicorn hello:app
Procfile
lanyrd.com/sdmbmk
VI. Processes
12factor.net/
lanyrd.com/sdmbmk
$ foreman start
Start the app
lanyrd.com/sdmbmk
X. Dev/prod parity
12factor.net/dev-prod-parity
lanyrd.com/sdmbmk
$ pip freeze > requirements.txt
Freeze dependencies
lanyrd.com/sdmbmk
II. Dependencies
12factor.net/
lanyrd.com/sdmbmk
Store the app in git
devcenter.heroku.com/articles/git
lanyrd.com/sdmbmk
venv
*.pyc
.gitignore
lanyrd.com/sdmbmk
$ git init
$ git add .
$ git commit -m "initial commit"
Store the app in git
lanyrd.com/sdmbmk
I. Single codebase
12factor.net/
lanyrd.com/sdmbmk
Create and deploy 

the application
lanyrd.com/sdmbmk
$ heroku create
$ git push heroku master
...
-----> Launching... done, v2
http://happy-pycon-2015.herokuapp.com
deployed to Heroku
$ heroku open
Create and deploy the app
lanyrd.com/sdmbmk
V. Build, release, run
12factor.net/build-release-run
lanyrd.com/sdmbmk
Logging
lanyrd.com/sdmbmk
$ heroku logs --tail
Viewing logs
lanyrd.com/sdmbmk
import os
from flask import Flask
!
app = Flask(__name__)
!
import logging
logging.basicConfig(level=logging.DEBUG)
!
@app.route('/')
def hello():
logging.info("saying hello")
return 'Hello World!'
hello.py
lanyrd.com/sdmbmk
$ git add .
$ git commit -m "add logging"
$ git push heroku master
Commit and deploy again
lanyrd.com/sdmbmk
$ heroku logs --tail
Viewing logs
lanyrd.com/sdmbmk
XI. Logs as event streams
12factor.net/
lanyrd.com/sdmbmk
Configuration variables
devcenter.heroku.com/articles/config-vars
lanyrd.com/sdmbmk
import os
import logging
from flask import Flask
!
app = Flask(__name__)
logging.basicConfig(level=logging.DEBUG)
!
@app.route('/')
def hello():
logging.info("saying hello")
name = os.environ.get('NAME', 'World')
return 'Hello {}!'.format(name)
hello.py
lanyrd.com/sdmbmk
$ NAME=David foreman start
Try it out locally
lanyrd.com/sdmbmk
$ echo "NAME=David" > .env
Store local env vars in .env
(don’t forget to add it to .gitignore)
lanyrd.com/sdmbmk
$ foreman start
Try it out locally
lanyrd.com/sdmbmk
$ git add .
$ git commit -m "add name"
$ git push heroku master
Commit and deploy
lanyrd.com/sdmbmk
$ heroku config:set NAME=David
Setting config vars and restarting happy-pycon-2015... done, v6
!
$ heroku config:get NAME
David
!
$ heroku config
=== happy-pycon-2015 Config Vars
NAME: David
!
$ heroku config:unset NAME
Unsetting NAME and restarting happy-pycon-2015... done, v7
Managing config vars
lanyrd.com/sdmbmk
III. Store config in the environment
12factor.net/
lanyrd.com/sdmbmk
Releases
devcenter.heroku.com/articles/releases
lanyrd.com/sdmbmk
$ heroku releases
=== happy-pycon-2015 Releases
v7 Remove NAME config vars dgouldin@heroku.com 2015/04/07 12:41:49
v6 Deploy df3cf06 dgouldin@heroku.com 2015/04/07 12:40:32
v5 Set NAME config vars dgouldin@heroku.com 2015/04/07 12:35:30
v4 Deploy 5bebf9b dgouldin@heroku.com 2015/04/07 12:34:27
v3 Deploy 69398b3 dgouldin@heroku.com 2015/04/07 12:18:08
v2 Enable Logplex dgouldin@heroku.com 2015/04/07 12:16:20
v1 Initial release dgouldin@heroku.com 2015/04/07 12:16:17
Release history
lanyrd.com/sdmbmk
I. One codebase, many deploys
12factor.net/
lanyrd.com/sdmbmk
Addons
addons.heroku.com
lanyrd.com/sdmbmk
$ heroku addons:create rediscloud
Adding rediscloud on happy-pycon-2015... done, v8 (free)
Use `heroku addons:docs rediscloud` to view documentation.
Adding an addon
lanyrd.com/sdmbmk
import os
import redis
from flask import Flask
!
app = Flask(__name__)
db = redis.from_url(os.environ['REDISCLOUD_URL'])
!
@app.route('/')
def hello():
name = db.get(‘name') or 'World'
return 'Hello %s!' % name
!
@app.route('/setname/<name>')
def setname(name):
db.set('name', name)
return 'Name updated.'
hello.py
lanyrd.com/sdmbmk
IV. Treat backing services as attached resources
12factor.net/
lanyrd.com/sdmbmk
$ pip install redis
$ pip freeze > requirements.txt
Dependencies
lanyrd.com/sdmbmk
$ git add .
$ git commit -m "use redis for name"
$ git push heroku master
Commit and deploy
lanyrd.com/sdmbmk
X. Dev/prod parity?
Uh oh…
lanyrd.com/sdmbmk
$ foreman start
13:03:34 web.1 | started with pid 24492
...
13:03:34 web.1 | 2015-04-07 13:03:34 [24495] [ERROR] Exception in worker process:
13:03:34 web.1 | Traceback (most recent call last):
...
13:03:34 web.1 | KeyError: 'REDISCLOUD_URL'
...
13:03:34 web.1 | 2015-04-07 13:03:34 [24495] [INFO] Worker exiting (pid: 24495)
13:03:34 web.1 | 2015-04-07 13:03:34 [24492] [INFO] Shutting down: Master
13:03:34 web.1 | 2015-04-07 13:03:34 [24492] [INFO] Reason: Worker failed to boot.
13:03:34 web.1 | exited with code 3
13:03:34 system | sending SIGTERM to all processes
SIGTERM received
Uh oh…
lanyrd.com/sdmbmk
Some solutions:
Only run remotely
Homebrew - brew.sh
Vagrant - vagrantup.com
Docker - docker.io
lanyrd.com/sdmbmk
Scaling and performance
devcenter.heroku.com/articles/scaling
lanyrd.com/sdmbmk
$ heroku ps:scale web=2
Scaling dynos... done, now running web at 2:1X.
!
$ heroku ps:scale web=10
Scaling dynos... done, now running web at 10:1X.
!
$ heroku ps:scale web=5:2X
Scaling dynos... done, now running web at 5:2X.
!
$ heroku ps:scale web=1:PX
Scaling dynos... done, now running web at 1:PX.
!
$ heroku ps:scale web=1:1X
Scaling dynos... done, now running web at 1:1X.
Scaling
lanyrd.com/sdmbmk
Understanding performance
devcenter.heroku.com/articles/optimizing-dyno-usage
lanyrd.com/sdmbmk
VIII. Concurrency via processes
12factor.net/
lanyrd.com/sdmbmk
$ heroku labs:enable log-runtime-metrics
$ heroku restart
!
$ heroku logs --tail
2015-04-07T17:19:30.746857+00:00 heroku[web.1]: source=web.1 dyno=heroku.
23939571.b4d17f84-50f5-4e2f-9fb1-b2124db4addb sample#memory_total=17.86MB
sample#memory_rss=17.85MB sample#memory_cache=0.00MB sample#memory_swap=0.00MB
sample#memory_pgpgin=5311pages sample#memory_pgpgout=740pages
!
2015-04-07T17:19:50.787234+00:00 heroku[web.1]: source=web.1 dyno=heroku.
23939571.b4d17f84-50f5-4e2f-9fb1-b2124db4addb sample#memory_total=17.86MB
sample#memory_rss=17.85MB sample#memory_cache=0.00MB sample#memory_swap=0.00MB
sample#memory_pgpgin=5311pages sample#memory_pgpgout=740pages
log-runtime-metrics
lanyrd.com/sdmbmk
Dashboard
metrics
organization
add-ons marketplace
lanyrd.com/sdmbmk
Metrics
devcenter.heroku.com/articles/metrics
lanyrd.com/sdmbmk
Organizations
devcenter.heroku.com/categories/organization-accounts
lanyrd.com/sdmbmk
Add-ons Marketplace
lanyrd.com/sdmbmk
Papertrail
lanyrd.com/sdmbmk
Rollbar
lanyrd.com/sdmbmk
New Relic
lanyrd.com/sdmbmk
And many more …
addons.heroku.com
lanyrd.com/sdmbmk
Github Integration
devcenter.heroku.com/articles/github-integration
lanyrd.com/sdmbmk
Automatic Deploys
lanyrd.com/sdmbmk
Release Diffs
lanyrd.com/sdmbmk
Heroku Button
1 click to a deployed Heroku app
lanyrd.com/sdmbmk
app.json
lanyrd.com/sdmbmk
README.md
[![Deploy](https://www.herokucdn.com/deploy/button.png)]
(https://heroku.com/deploy?template=https://github.com/
dgouldin/django-playground)
lanyrd.com/sdmbmk
Try it yourself!
github.com/dgouldin/django-playground
lanyrd.com/sdmbmk
Bonus: Platform API
devcenter.heroku.com/categories/platform-api
lanyrd.com/sdmbmk
>>> import json
>>> import requests # python-requests.org
!
>>> heroku = requests.session()
>>> heroku.auth = ('', '{INSERT HEROKU API TOKEN HERE}')
>>> heroku.headers['Accept'] = 'application/vnd.heroku+json; version=3'
>>> heroku.headers['Content-Type'] = 'application/json'
REST API basics
lanyrd.com/sdmbmk
>>> heroku.get('https://api.heroku.com/apps/happy-pycon-2015').json()
{u'archived_at': None,
...
u'web_url': u'http://dgouldin.herokuapp.com/'}
!
>>> heroku.get('https://api.heroku.com/apps/happy-pycon-2015/config-vars').json()
[35] :
{u'NAME': u'David',
u'REDISCLOUD_URL': u'{REDACTED}'}
!
>>> body = json.dumps({'NAME': 'Robot'})
>>> heroku.patch('https://api.heroku.com/apps/happy-pycon-2015/config-vars', body)
App info; config vars
lanyrd.com/sdmbmk
>>> heroku.get('https://api.heroku.com/apps/happy-pycon-2015/formation').json()
[{u'command': u'gunicorn hello:app',
u'created_at': u'2015-04-06T16:42:24Z',
u'id': u'928f6618-a0e2-4ded-95ec-e3a23a7795f0',
u'quantity': 2,
u'size': u'1X',
u'type': u'web',
u'updated_at': u'2015-04-06T18:50:02Z'}]
!
>>> body = json.dumps({'quantity': 4})
>>> heroku.patch('https://api.heroku.com/apps/dgouldin/formation/web', body)
Scaling
lanyrd.com/sdmbmk
Questions and Free Play
dgouldin@heroku.com
@dgouldin

More Related Content

PPTX
Amazon Kinesis Video Streams WebRTC 使ってみた
PDF
AWS Well-Architected Security とベストプラクティス
PDF
20200818 AWS Black Belt Online Seminar AWS Shield Advanced
PDF
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-
PDF
今夜わかるWebアプリケーション脆弱性診断 (OWASP Day 758 / 2018)
PDF
AWS Black Belt Online Seminar 2016 AWS CloudFormation
PDF
아키텍처 현대화 분야 신규 서비스 - 주성식, AWS 솔루션즈 아키텍트 :: AWS re:Invent re:Cap 2021
PDF
AbemaTVの動画配信を支えるサーバーサイドシステム
Amazon Kinesis Video Streams WebRTC 使ってみた
AWS Well-Architected Security とベストプラクティス
20200818 AWS Black Belt Online Seminar AWS Shield Advanced
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-
今夜わかるWebアプリケーション脆弱性診断 (OWASP Day 758 / 2018)
AWS Black Belt Online Seminar 2016 AWS CloudFormation
아키텍처 현대화 분야 신규 서비스 - 주성식, AWS 솔루션즈 아키텍트 :: AWS re:Invent re:Cap 2021
AbemaTVの動画配信を支えるサーバーサイドシステム

What's hot (20)

PDF
分散型IDと検証可能なアイデンティティ技術概要
PDF
Awsのインフラをデザインパターン駆使して設計構築
PDF
DevOps with Database on AWS
PDF
클라우드 보안 위협 동향과 통합 보안 전략 - 김준호 과장, SECUI :: AWS Summit Seoul 2019
PDF
AWS로 사용자 천만 명 서비스 만들기 (윤석찬)- 클라우드 태권 2015
PPTX
WebRTC SFU mediasoup sample
PDF
ここが良かったDatadog
PDF
「これ危ない設定じゃないでしょうか」とヒアリングするための仕組み @AWS Summit Tokyo 2018
PDF
実環境にTerraform導入したら驚いた
PDF
DroidKaigi 2019 Chrome Custom Tabsの仕組みから学ぶプロセス間通信
PDF
AWS Black Belt Online Seminar 2017 AWS Shield
PDF
Amazon SageMaker で始める機械学習
PPTX
글로벌 기업들의 효과적인 데이터 분석을 위한 Data Lake 구축 및 분석 사례 - 김준형 (AWS 솔루션즈 아키텍트)
PDF
20190130 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...
PPTX
Data Mesh in Azure using Cloud Scale Analytics (WAF)
PDF
천만 사용자를 위한 AWS 아키텍처 보안 모범 사례 (윤석찬, 테크에반젤리스트)
PDF
機械学習モデルのサービングとは?
PPTX
機械学習用のデータを準備する Amazon SageMaker Data Wrangler - ノーコードで前処理から学習まで
PPTX
Airflow를 이용한 데이터 Workflow 관리
PDF
AWS Black Belt Online Seminar 2016 AWS上でのActive Directory構築
分散型IDと検証可能なアイデンティティ技術概要
Awsのインフラをデザインパターン駆使して設計構築
DevOps with Database on AWS
클라우드 보안 위협 동향과 통합 보안 전략 - 김준호 과장, SECUI :: AWS Summit Seoul 2019
AWS로 사용자 천만 명 서비스 만들기 (윤석찬)- 클라우드 태권 2015
WebRTC SFU mediasoup sample
ここが良かったDatadog
「これ危ない設定じゃないでしょうか」とヒアリングするための仕組み @AWS Summit Tokyo 2018
実環境にTerraform導入したら驚いた
DroidKaigi 2019 Chrome Custom Tabsの仕組みから学ぶプロセス間通信
AWS Black Belt Online Seminar 2017 AWS Shield
Amazon SageMaker で始める機械学習
글로벌 기업들의 효과적인 데이터 분석을 위한 Data Lake 구축 및 분석 사례 - 김준형 (AWS 솔루션즈 아키텍트)
20190130 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...
Data Mesh in Azure using Cloud Scale Analytics (WAF)
천만 사용자를 위한 AWS 아키텍처 보안 모범 사례 (윤석찬, 테크에반젤리스트)
機械学習モデルのサービングとは?
機械学習用のデータを準備する Amazon SageMaker Data Wrangler - ノーコードで前処理から学習まで
Airflow를 이용한 데이터 Workflow 관리
AWS Black Belt Online Seminar 2016 AWS上でのActive Directory構築
Ad

Similar to Heroku 101 py con 2015 - David Gouldin (20)

ODP
PPTX
Introduction to Heroku
PDF
Symfony Deployments on Heroku
PDF
Introduction to PaaS and Heroku
PDF
Prototyping in the cloud
PPTX
Introduction to Heroku - CCT London 2013
PDF
Heroku and Rails Applications
PDF
Quick and Dirty Python Deployments with Heroku
PDF
Heroku webcastdeck+20130828
PDF
Cloudcamp Athens 2011 Presenting Heroku
PDF
Heroku Tips and Hacks
PPTX
2012 coscup - Build your PHP application on Heroku
PPTX
Getting Started with Heroku
PPSX
Introducing Heroku for Beginners
PDF
Building a Django App on Heroku
PPTX
Architect Track Heroku - A Polyglot Platform [Architecture & Add-ons]By Ashis...
PPTX
Heroku - A ployglot Platform (Add-on)
PPTX
GIT, RVM, FIRST HEROKU APP
PDF
Cloud Platform as a Service: Heroku
PDF
Heroku, Cloud Conf Varna - 22.02.2014
Introduction to Heroku
Symfony Deployments on Heroku
Introduction to PaaS and Heroku
Prototyping in the cloud
Introduction to Heroku - CCT London 2013
Heroku and Rails Applications
Quick and Dirty Python Deployments with Heroku
Heroku webcastdeck+20130828
Cloudcamp Athens 2011 Presenting Heroku
Heroku Tips and Hacks
2012 coscup - Build your PHP application on Heroku
Getting Started with Heroku
Introducing Heroku for Beginners
Building a Django App on Heroku
Architect Track Heroku - A Polyglot Platform [Architecture & Add-ons]By Ashis...
Heroku - A ployglot Platform (Add-on)
GIT, RVM, FIRST HEROKU APP
Cloud Platform as a Service: Heroku
Heroku, Cloud Conf Varna - 22.02.2014
Ad

More from Heroku (10)

PPTX
Heroku Connect: The New Way to Build Connected Customer Applications
PDF
Mattt Thompson at Heroku's Waza 2013: Mobile is not Different
PDF
Codeacademy's Linda Liukas at Heroku's Waza 2013: Code is Everyone's Business
PDF
Rob Sullivan at Heroku's Waza 2013: Your Database -- A Story of Indifference
PDF
Heroku's Ryan Smith at Waza 2013: Predictable Failure
PDF
Librato's Joseph Ruscio at Heroku's 2013: Instrumenting 12-Factor Apps
PDF
Noah Zoschke at Waza 2013: Heroku Secrets
PDF
Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are...
PDF
AirBnB's Jack Lawson at Heroku's Waza: Dismantling the Monorail
PDF
Kirby Ferguson at Heroku's Waza 2013
Heroku Connect: The New Way to Build Connected Customer Applications
Mattt Thompson at Heroku's Waza 2013: Mobile is not Different
Codeacademy's Linda Liukas at Heroku's Waza 2013: Code is Everyone's Business
Rob Sullivan at Heroku's Waza 2013: Your Database -- A Story of Indifference
Heroku's Ryan Smith at Waza 2013: Predictable Failure
Librato's Joseph Ruscio at Heroku's 2013: Instrumenting 12-Factor Apps
Noah Zoschke at Waza 2013: Heroku Secrets
Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are...
AirBnB's Jack Lawson at Heroku's Waza: Dismantling the Monorail
Kirby Ferguson at Heroku's Waza 2013

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
MYSQL Presentation for SQL database connectivity
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
KodekX | Application Modernization Development
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Electronic commerce courselecture one. Pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Cloud computing and distributed systems.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Spectroscopy.pptx food analysis technology
PDF
Machine learning based COVID-19 study performance prediction
Encapsulation_ Review paper, used for researhc scholars
MYSQL Presentation for SQL database connectivity
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
KodekX | Application Modernization Development
Understanding_Digital_Forensics_Presentation.pptx
Unlocking AI with Model Context Protocol (MCP)
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Dropbox Q2 2025 Financial Results & Investor Presentation
Electronic commerce courselecture one. Pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Cloud computing and distributed systems.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
The AUB Centre for AI in Media Proposal.docx
Big Data Technologies - Introduction.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Spectroscopy.pptx food analysis technology
Machine learning based COVID-19 study performance prediction

Heroku 101 py con 2015 - David Gouldin