Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Cloud Computing for Hackers
Search
Giovanni Collazo
October 23, 2012
Programming
3
630
Cloud Computing for Hackers
Presented on workshop at Universidad de Puerto Rico, Rio Piedras.
Giovanni Collazo
October 23, 2012
Tweet
Share
More Decks by Giovanni Collazo
See All by Giovanni Collazo
Mis refranes favoritos
gcollazo
7
750
BarcampVSJ
gcollazo
4
63
The Future
gcollazo
0
150
Blimp - How it's Made
gcollazo
5
300
Naming and branding for hackers
gcollazo
0
230
Receta para conseguir "guisos" mientras se estudia a tiempo completo
gcollazo
4
460
Other Decks in Programming
See All in Programming
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.2k
Quine, Polyglot, 良いコード
qnighy
4
650
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
Outline View in SwiftUI
1024jp
1
330
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
240
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Designing Experiences People Love
moore
138
23k
Building Your Own Lightsaber
phodgson
103
6.1k
Thoughts on Productivity
jonyablonski
67
4.3k
Fireside Chat
paigeccino
34
3k
Typedesign – Prime Four
hannesfritz
40
2.4k
Being A Developer After 40
akosma
87
590k
Statistics for Hackers
jakevdp
796
220k
Visualization
eitanlees
145
15k
Unsuck your backbone
ammeep
668
57k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Transcript
Cloud Computing for Hackers
Thanks for showing up
We are going to move fast
I will stop for questions
Giovanni Collazo @gcollazo
None
None
Hacker
“jakel”
“To programmers, ‘hacker’ connotes mastery in the most literal sense:
someone who can make a computer do what he wants—whether the computer wants to or not” - Paul Graham
“It can be either a compliment or an insult. It's
called a hack when you do something in an ugly way. But when you do something so clever that you somehow beat the system, that's also called a hack.” - Paul Graham
None
None
None
None
None
If you are here you are a Hacker
So, what’s cloud computing?
a computer in the sky
a computer over network
a computer somewhere on the internet
elastic
providing service as a utility
the illusion of infinite supply
Why so much attention?
Paradigm shift
None
Everything talks to the network
All computers are over the network
Does it matter if the other side of the cable
is in the same building?
For most apps it doesn’t matter
So, I don’t have to buy and maintain servers?
None
Why Hackers should care?
We can deploy a server in seconds
We can deploy hundreds in minutes
Pay for what you use
New kinds of apps are possible
New toy to play with
How many servers they have?
It’s been reported that AWS has somewhere around 500,000
That’s not enough
They are enough because the are virtualized
What’s this virtualization thing?
Hardware virtualization or platform virtualization refers to the creation of
a virtual machine that acts like a real computer with an operating system - Wikipedia
One physical machine can run multiple virtual machines
They share the resources of the physical machine
XEN
XEN x86, x86_64, IA64, ARM
XEN Windows, Linux, Solaris, BSD
They look like “real” machines over the network
They are cheap to run
None
This is specially cool for scaling web apps
Modern web apps are designed to scale horizontally
That means that to support more traffic you just add
more “cheap” machines
...instead of using really big, powerful and “expensive” machines
What does the architecture of a web app looks like?
App Server HTTP Request HTTP Response DB
App Server HTTP Request HTTP Response DB Cache
App Server HTTP Request HTTP Response Cache DB Reads &
Writes
App Server HTTP Request HTTP Response Cache DB Reads &
Writes App Server Load Balancer
Load Balancer App Server App Server App Server App Server
DB Read Slave DB Read Slave Cache Reads DB Master Writes Replication HTTP Request HTTP Response
Load Balancer App Server App Server App Server App Server
Cache DB01 HTTP Request HTTP Response DB02 DB03 Shard01 Shard10 Shard11 Shard20 Shard21 Shard30 Reads & Writes Reads & Writes
what if AWS goes down?
AWS America East Rackspace OpenCloud DNS
18 million visitors per month 3 million + users 410TB
of data
12 Employees
30 million users 150 million photos
3 engineers
Sold for $1 billion to Facebook
OK. Got it! How do I use the cloud?
There are many approaches to “the cloud” but we are
going to talk about 2
The ones I think you’ll care about
None
you rent an instance
you manage your OS
upgrade packages
take care of security
... and availability
it’s the closest to renting a physical server on a
data center
maximum control
management over web console or api
None
They provide a container for your app
Easy deployment
git push heroku master
They take care of OS level issues
Super easy scaling
They enforce good app design
Less control over the environment
They run on top of AWS
What should I use?
Well, it depends
Understand the AWS model
Start with Heroku
Move to AWS when it’s absolutely necessary
None
Hands-on
None
Login to the AWS console
Create a Linux instance
Install Apache and PHP
Create a simple PHP script
Warning
Let’s do it
https://blimp.signin.aws.amazon.com/console
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
chmod 600 keyfile.pem
ssh -i keyname.pem ubuntu@hostname
sudo aptitude install apache2
sudo aptitude install php5 libapache2-mod-php5
cd /var/www/
sudo mv index.html index.php
sudo vim index.php
<?php echo 'AppServer: ' . gethostname(); ?>
Now what?
Live demo
Creating an image from a running instance
Launch an instance from an image
Creating an ELB
Me gusta
ProTips™
Free Tier
Micro instances are throttled down after a few minutes of
heavy use
Using the biggest available instance size gets you a “full”
machine
Chaos Monkey
Homework: Try to learn some Python
That’s it for today... Questions
Day 2
Cloud Computing for Hackers
None
Load Balancer Web Dyno Web Dyno Worker Dyno Cron Dyno
HTTP Request HTTP Response
Load Balancer Web Dyno Web Dyno Worker Dyno Cron Dyno
HTTP Request HTTP Response Ruby, Python, Scala, Java, Javascript, PHP
They do SysOps
You make web apps
Let’s try it
Setup a Python dev environment
Create a virtualenv for our first project
Create the simplest web app ever made
Deploy to Heroku
Make changes to the app
Deploy again
Start * tested on Mac OSX
mkdir ~/.virtualenvs
sudo easy_install pip
sudo pip install virtualenvwrapper
vim ~/.bash_profile
export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh .bash_profile
source ~/.bash_profile
cd ~/Desktop mkdir myapp cd myapp
mkvirtualenv myapp
pip install flask pip freeze > requirements.txt
app.py import os from flask import Flask app = Flask(__name__)
app.debug = True @app.route("/") def hello(): return 'Hello: {}'.format(os.uname()[1]) if __name__ == "__main__": port = int(os.environ.get('PORT', 5000)) app.run(host='0.0.0.0', port=port)
python app.py open http://localhost:5000
vim Procfile
web: python app.py Procfile
git init git add . git commit -m ‘Initial Commit’
Install the Heroku Toolbelt https://toolbelt.heroku.com
Sign up to Heroku https://api.heroku.com/signup
heroku login
heroku create
git push heroku master
heroku open
import os from flask import Flask app = Flask(__name__) app.debug
= True @app.route("/") def hello(): return 'Bye: {}'.format(os.uname()[1]) if __name__ == "__main__": port = int(os.environ.get('PORT', 5000)) app.run(host='0.0.0.0', port=port) app.py
git commit -am ‘Small copy change’
git push heroku master
heroku open
Something more exiting, please * tested on Mac OSX
Let’s use Redis
brew install redis * Mac OSX only
pip install redis
pip freeze > requirements.txt
import os import redis redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379/0') redis =
redis.from_url(redis_url) store.py
mkdir templates vim templates/index.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>The List</title> </head> <body>
<ul> {% for item in the_list %} <li>{{ item }}</li> {% endfor%} </ul> </body> </html> index.html
import os import time from flask import Flask from flask
import render_template from store import redis app = Flask(__name__) app.debug = True @app.route("/") def hello(): redis.rpush('thelist', 'Hello: {} - {}'.format(os.uname()[1], time.time())) the_list = redis.lrange('thelist', 0, -1) return render_template('index.html', the_list=the_list) if __name__ == "__main__": port = int(os.environ.get('PORT', 5000)) app.run(host='0.0.0.0', port=port) app.py
git add . git commit -am ‘Added redis’
heroku addons:add redistogo:nano
git push heroku master heroku open
How can I manage the app?
heroku ps
heroku logs
heroku config
ProTips™
heroku logs --tail
heroku run bash
heroku maintenance:on heroku maintenance:off
Prevent app from sleeping http://pingdom.com
Use foreman locally to run multiple app processes
web: python app.py redis: redis-server Procfile.local
foreman start -f Profile.local
Q&A
Giovanni Collazo @gcollazo