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
790
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
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
470
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
540
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
760
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
770
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
280
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
3
720
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
useSyncExternalStoreを使いまくる
ssssota
6
1k
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
100
Recoilを剥がしている話
kirik
5
6.7k
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
335
57k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
What's in a price? How to price your products and services
michaelherold
243
12k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Unsuck your backbone
ammeep
669
57k
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