Slide 1

Slide 1 text

Cloud Computing for Hackers

Slide 2

Slide 2 text

Thanks for showing up

Slide 3

Slide 3 text

We are going to move fast

Slide 4

Slide 4 text

I will stop for questions

Slide 5

Slide 5 text

Giovanni Collazo @gcollazo

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Hacker

Slide 9

Slide 9 text

“jakel”

Slide 10

Slide 10 text

“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

Slide 11

Slide 11 text

“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

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

If you are here you are a Hacker

Slide 18

Slide 18 text

So, what’s cloud computing?

Slide 19

Slide 19 text

a computer in the sky

Slide 20

Slide 20 text

a computer over network

Slide 21

Slide 21 text

a computer somewhere on the internet

Slide 22

Slide 22 text

elastic

Slide 23

Slide 23 text

providing service as a utility

Slide 24

Slide 24 text

the illusion of infinite supply

Slide 25

Slide 25 text

Why so much attention?

Slide 26

Slide 26 text

Paradigm shift

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Everything talks to the network

Slide 29

Slide 29 text

All computers are over the network

Slide 30

Slide 30 text

Does it matter if the other side of the cable is in the same building?

Slide 31

Slide 31 text

For most apps it doesn’t matter

Slide 32

Slide 32 text

So, I don’t have to buy and maintain servers?

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Why Hackers should care?

Slide 35

Slide 35 text

We can deploy a server in seconds

Slide 36

Slide 36 text

We can deploy hundreds in minutes

Slide 37

Slide 37 text

Pay for what you use

Slide 38

Slide 38 text

New kinds of apps are possible

Slide 39

Slide 39 text

New toy to play with

Slide 40

Slide 40 text

How many servers they have?

Slide 41

Slide 41 text

It’s been reported that AWS has somewhere around 500,000

Slide 42

Slide 42 text

That’s not enough

Slide 43

Slide 43 text

They are enough because the are virtualized

Slide 44

Slide 44 text

What’s this virtualization thing?

Slide 45

Slide 45 text

Hardware virtualization or platform virtualization refers to the creation of a virtual machine that acts like a real computer with an operating system - Wikipedia

Slide 46

Slide 46 text

One physical machine can run multiple virtual machines

Slide 47

Slide 47 text

They share the resources of the physical machine

Slide 48

Slide 48 text

XEN

Slide 49

Slide 49 text

XEN x86, x86_64, IA64, ARM

Slide 50

Slide 50 text

XEN Windows, Linux, Solaris, BSD

Slide 51

Slide 51 text

They look like “real” machines over the network

Slide 52

Slide 52 text

They are cheap to run

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

This is specially cool for scaling web apps

Slide 55

Slide 55 text

Modern web apps are designed to scale horizontally

Slide 56

Slide 56 text

That means that to support more traffic you just add more “cheap” machines

Slide 57

Slide 57 text

...instead of using really big, powerful and “expensive” machines

Slide 58

Slide 58 text

What does the architecture of a web app looks like?

Slide 59

Slide 59 text

App Server HTTP Request HTTP Response DB

Slide 60

Slide 60 text

App Server HTTP Request HTTP Response DB Cache

Slide 61

Slide 61 text

App Server HTTP Request HTTP Response Cache DB Reads & Writes

Slide 62

Slide 62 text

App Server HTTP Request HTTP Response Cache DB Reads & Writes App Server Load Balancer

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

what if AWS goes down?

Slide 66

Slide 66 text

AWS America East Rackspace OpenCloud DNS

Slide 67

Slide 67 text

18 million visitors per month 3 million + users 410TB of data

Slide 68

Slide 68 text

12 Employees

Slide 69

Slide 69 text

30 million users 150 million photos

Slide 70

Slide 70 text

3 engineers

Slide 71

Slide 71 text

Sold for $1 billion to Facebook

Slide 72

Slide 72 text

OK. Got it! How do I use the cloud?

Slide 73

Slide 73 text

There are many approaches to “the cloud” but we are going to talk about 2

Slide 74

Slide 74 text

The ones I think you’ll care about

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

you rent an instance

Slide 77

Slide 77 text

you manage your OS

Slide 78

Slide 78 text

upgrade packages

Slide 79

Slide 79 text

take care of security

Slide 80

Slide 80 text

... and availability

Slide 81

Slide 81 text

it’s the closest to renting a physical server on a data center

Slide 82

Slide 82 text

maximum control

Slide 83

Slide 83 text

management over web console or api

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

They provide a container for your app

Slide 86

Slide 86 text

Easy deployment

Slide 87

Slide 87 text

git push heroku master

Slide 88

Slide 88 text

They take care of OS level issues

Slide 89

Slide 89 text

Super easy scaling

Slide 90

Slide 90 text

They enforce good app design

Slide 91

Slide 91 text

Less control over the environment

Slide 92

Slide 92 text

They run on top of AWS

Slide 93

Slide 93 text

What should I use?

Slide 94

Slide 94 text

Well, it depends

Slide 95

Slide 95 text

Understand the AWS model

Slide 96

Slide 96 text

Start with Heroku

Slide 97

Slide 97 text

Move to AWS when it’s absolutely necessary

Slide 98

Slide 98 text

No content

Slide 99

Slide 99 text

Hands-on

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

Login to the AWS console

Slide 102

Slide 102 text

Create a Linux instance

Slide 103

Slide 103 text

Install Apache and PHP

Slide 104

Slide 104 text

Create a simple PHP script

Slide 105

Slide 105 text

Warning

Slide 106

Slide 106 text

Let’s do it

Slide 107

Slide 107 text

https://blimp.signin.aws.amazon.com/console

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

No content

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

No content

Slide 115

Slide 115 text

No content

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

No content

Slide 120

Slide 120 text

No content

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

No content

Slide 123

Slide 123 text

chmod 600 keyfile.pem

Slide 124

Slide 124 text

ssh -i keyname.pem ubuntu@hostname

Slide 125

Slide 125 text

sudo aptitude install apache2

Slide 126

Slide 126 text

sudo aptitude install php5 libapache2-mod-php5

Slide 127

Slide 127 text

cd /var/www/

Slide 128

Slide 128 text

sudo mv index.html index.php

Slide 129

Slide 129 text

sudo vim index.php

Slide 130

Slide 130 text

Slide 131

Slide 131 text

Now what?

Slide 132

Slide 132 text

Live demo

Slide 133

Slide 133 text

Creating an image from a running instance

Slide 134

Slide 134 text

Launch an instance from an image

Slide 135

Slide 135 text

Creating an ELB

Slide 136

Slide 136 text

Me gusta

Slide 137

Slide 137 text

ProTips™

Slide 138

Slide 138 text

Free Tier

Slide 139

Slide 139 text

Micro instances are throttled down after a few minutes of heavy use

Slide 140

Slide 140 text

Using the biggest available instance size gets you a “full” machine

Slide 141

Slide 141 text

Chaos Monkey

Slide 142

Slide 142 text

Homework: Try to learn some Python

Slide 143

Slide 143 text

That’s it for today... Questions

Slide 144

Slide 144 text

Day 2

Slide 145

Slide 145 text

Cloud Computing for Hackers

Slide 146

Slide 146 text

No content

Slide 147

Slide 147 text

Load Balancer Web Dyno Web Dyno Worker Dyno Cron Dyno HTTP Request HTTP Response

Slide 148

Slide 148 text

Load Balancer Web Dyno Web Dyno Worker Dyno Cron Dyno HTTP Request HTTP Response Ruby, Python, Scala, Java, Javascript, PHP

Slide 149

Slide 149 text

They do SysOps

Slide 150

Slide 150 text

You make web apps

Slide 151

Slide 151 text

Let’s try it

Slide 152

Slide 152 text

Setup a Python dev environment

Slide 153

Slide 153 text

Create a virtualenv for our first project

Slide 154

Slide 154 text

Create the simplest web app ever made

Slide 155

Slide 155 text

Deploy to Heroku

Slide 156

Slide 156 text

Make changes to the app

Slide 157

Slide 157 text

Deploy again

Slide 158

Slide 158 text

Start * tested on Mac OSX

Slide 159

Slide 159 text

mkdir ~/.virtualenvs

Slide 160

Slide 160 text

sudo easy_install pip

Slide 161

Slide 161 text

sudo pip install virtualenvwrapper

Slide 162

Slide 162 text

vim ~/.bash_profile

Slide 163

Slide 163 text

export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh .bash_profile

Slide 164

Slide 164 text

source ~/.bash_profile

Slide 165

Slide 165 text

cd ~/Desktop mkdir myapp cd myapp

Slide 166

Slide 166 text

mkvirtualenv myapp

Slide 167

Slide 167 text

pip install flask pip freeze > requirements.txt

Slide 168

Slide 168 text

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)

Slide 169

Slide 169 text

python app.py open http://localhost:5000

Slide 170

Slide 170 text

vim Procfile

Slide 171

Slide 171 text

web: python app.py Procfile

Slide 172

Slide 172 text

git init git add . git commit -m ‘Initial Commit’

Slide 173

Slide 173 text

Install the Heroku Toolbelt https://toolbelt.heroku.com

Slide 174

Slide 174 text

Sign up to Heroku https://api.heroku.com/signup

Slide 175

Slide 175 text

heroku login

Slide 176

Slide 176 text

heroku create

Slide 177

Slide 177 text

git push heroku master

Slide 178

Slide 178 text

heroku open

Slide 179

Slide 179 text

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

Slide 180

Slide 180 text

git commit -am ‘Small copy change’

Slide 181

Slide 181 text

git push heroku master

Slide 182

Slide 182 text

heroku open

Slide 183

Slide 183 text

Something more exiting, please * tested on Mac OSX

Slide 184

Slide 184 text

Let’s use Redis

Slide 185

Slide 185 text

brew install redis * Mac OSX only

Slide 186

Slide 186 text

pip install redis

Slide 187

Slide 187 text

pip freeze > requirements.txt

Slide 188

Slide 188 text

import os import redis redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379/0') redis = redis.from_url(redis_url) store.py

Slide 189

Slide 189 text

mkdir templates vim templates/index.html

Slide 190

Slide 190 text

The List
    {% for item in the_list %}
  • {{ item }}
  • {% endfor%}
index.html

Slide 191

Slide 191 text

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

Slide 192

Slide 192 text

git add . git commit -am ‘Added redis’

Slide 193

Slide 193 text

heroku addons:add redistogo:nano

Slide 194

Slide 194 text

git push heroku master heroku open

Slide 195

Slide 195 text

How can I manage the app?

Slide 196

Slide 196 text

heroku ps

Slide 197

Slide 197 text

heroku logs

Slide 198

Slide 198 text

heroku config

Slide 199

Slide 199 text

ProTips™

Slide 200

Slide 200 text

heroku logs --tail

Slide 201

Slide 201 text

heroku run bash

Slide 202

Slide 202 text

heroku maintenance:on heroku maintenance:off

Slide 203

Slide 203 text

Prevent app from sleeping http://pingdom.com

Slide 204

Slide 204 text

Use foreman locally to run multiple app processes

Slide 205

Slide 205 text

web: python app.py redis: redis-server Procfile.local

Slide 206

Slide 206 text

foreman start -f Profile.local

Slide 207

Slide 207 text

Q&A

Slide 208

Slide 208 text

Giovanni Collazo @gcollazo