In this talk we distill 1.5 years of building and scaling web applications on the biggest and oldest cloud provider: Amazon Web Services. We discuss the various moving parts of AWS and how they're beneficial, some open-source counterparts that you can mix and match with, and how to set things up the right way from the start so that you won't end up with a big mess a year down the road. Though we will touch upon advanced topics such as Autoscale and Elastic Load Balancer, this talk is geared toward front-end developers who want a better understanding of what cloud environments actually are and how to properly harness them. Part 2 coming October 2013.
Intro to Scaling your Web App on the Cloud with AWS (for frontend developers) Part 1
1. Intro to Scaling your Web App
on the Cloud with AWS
(for Frontend Developers)
Mauvis Ledford
CTO, Pathbrite
@krunkosaurus
2. Goals of this talk
Philosophy
• Understand the common components of any Web Application Architecture and
how they apply to AWS.
• Understand the pieces that form “The Cloud” and the mindset you should have
when building upon it.
Action
• Regardless of your experience level, get you up and running and
experimenting with the AWS. It’s relatively cheap, fun, and the future of web
hosting.
2
3. Overview
What we’re going to cover
1. Server and Network Basics
2. Virtualization and the Cloud
3. Why Amazon Cloud?
4. The Cloud Philosophy
5. Major Components of the AWS Dashboard
6. Setting up Your First EC2 Instance
7. Further Reading
3
4. Server and Network Basics
The Lingo
• Server: Just a computer connected to the internet and used for serving data.
Usually fast and on 24x7. Your laptop can be a server.
• IP Address: A number assigned to each computer on a network used for
communication. For example 10.0.0.1.
• DNS: Also known as Domain Name System, is a distribution system that maps
IP address to domain names so that you don’t have to remember IP
addresses. For example “google.com” resolves to 74.125.224.67.
• Port: A communication endpoint that a servers listens for requests on. The
default port for webpages is port 80. When you type “google.com” in a web
browser, it is actually visiting: 74.125.224.67:80
• CDN: Or Content Delivery Network. Big, dumb, computers set up around the
world to serve your static assets really fast.
• Load Balancer: A piece of hardware or software that distributes load across
many servers.
4
5. Server and Network Basics
The Lingo
• Linux: Free, stable, secure, and open-source operating
system used by most servers. It comes in many
versions, all similar but with some differences. Our
preference is CentOS.
– Linux is based on Unix, an older operating system, and if
you use a Mac, it’s “guts” are based on Unix, too. That’s
why the command line is similar.
– Though Linux can come with a GUI, for performance
reasons, it is not generally installed on servers. You should
get comfortable with the command line if not already.
• Virtual Machine: A software abstraction that emulate the computer architecture and
functions of a real computer. A computer can contain many virtual machines with their
own operating systems each with an allotted percentage of CPU power and other
resources.
– The operating system doesn’t know or care that it’s running in a virtual environment.
– The Cloud consists of virtual machines.
5
Image
from:
h,p://www.y-‐tech.net/userfiles/image/Hos<ng/vps.jpg
6. Virtualization and the Cloud
The problem of unpredictable usage
6
From:
h,p://media.amazonwebservices.com/AWS_TCO_Web_Applica<ons.pdf
7. Virtualization and the Cloud
Why is virtualization such a big deal?
Running “bare metal” servers is expensive, wasteful, and slow to
upgrade.
• Most traditional servers sit underutilized, waiting for traffic spikes and that
idling CPU is wasted.
• Adding capacity involves ordering physical servers and going to a physical
location to set them up. This takes hours / days.
In cloud environments you spin up new virtual instances in minutes.
Shared hosting is limited and not scalable.
• Products like Dreamhost Shared Hosting works by putting lots of users on
one “bare metal” server on one OS. Users are restricted using the OS user
management and customers do not have root access. Security can be a
potential issue.
In cloud environments you have full root access to your own operating system
to setup and manage as you wish.
7
8. Why Amazon Cloud?
Why we chose AWS
• Reputation: Biggest and most well-
known cloud provider.
• Startup Cost: There is no upfront cost. Pay as little as $15/mo to run a
“micro” server instance for 1 month. Only run it for 1 hour? Your bill is $0.02.
• Customer base: AWS has an impressive customer base that includes
Dropbox, Netflix, Yelp, AirBnB, Reddit, and Pinterest. Amazon.com itself made
the switch in 2010.
• Scalability: Scale up when you need it, the moment you need it. Clone or spin
up new instances in minutes. Even learn to automate it so instances are
created and destroyed based on metrics like overall CPU usage.
• Everything in one place: From servers monitoring to DNS to it’s own CDN,
Amazon has setup all the robust services you need to make and scale a great
app all in one place.
8
9. Why Amazon Cloud?
Why we chose AWS
• Ability to mix and match: Not interested in Amazon’s managed database
service (RDS)? Setup your own MySQL instance on EC2 and run backups on
it yourself. You can pick and choose which AWS services you like and / or
stick to the open-source software you’re used to.
• Familiarity: For the most part, there is no “black box magic” with Amazon.
These are just virtualized Linux boxes in Data Centers around the globe. If
you’re familiar with servers in general then you’re already familiar with much of
AWS. There are no new command-line tricks or crazy proprietary workflows.
• Aggressive pricing: There are a lot of new Cloud contenders out there and
Amazon is constantly slashing prices to stay competitive.
• Constant innovation: Every few weeks there seems to be a new product or
service to make things easier.
9
10. The Cloud Philosophy
Fast and nimble
• Elasticity: Scale horizontally instead of
vertically.
• Parallelization: Strength in numbers.
• Decoupled Components: Every EC2
instance has it’s job.
• Automation: “If you’re SSH’ing in
you’re doing it wrong.”
Use Puppet, Chef, Salt, etc.
• Design for Failure: “Design for failure
and nothing will fail.”
10
Image
from:
h,p://minibeasts-‐bees.wikispaces.com/Images+%26+You+Tube+clips+of+bees
11. Components of AWS
This is the Cloud: 9 Regions worldwide, 4 in North America
• A Region is essentially a cluster of “Availability Zones”.
• Edge Locations are for Cloudfront CDN.
11
12. Components of AWS
Availability Zones
• Each Region contains two or more
“Availability Zones”.
• AZ’s are distinct locations within a region
that are engineered to be isolated from
failures in other AZ’s.
• AZ’s have low latency (sub 1-2ms) network
connectivity to other AZ’s in the same
region.
• By load balancing across separate Availability Zones, you can protect your
applications from the failure of a single location.
• TIP: It is not generally necessary to load balance across multiple Regions. It
requires traveling through the internet and is more technically and financially
challenging—only the biggest of the big AWS customers do it.
12
From:
h,p://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-‐regions-‐availability-‐zones.html
13. Components of AWS
The AWS Dashboard
ance
and Perform ring
C reate e o
Monit rts.
manag ers. le
serv and a
v i rtual
13
14. Components of AWS
Using Cloudwatch metrics
See up to 2 weeks of data on most every aspect of AWS from
EC2 to EBS drives. Create alerts on any metric including billing.
14
15. Components of AWS
The AWS Dashboard
ance
and Perform ring
C reate e o
Monit rts.
manag ers. le
serv and a
v i rtual
and
cheap e.
Dirt nkabl
Unsi ti c
Put all sta
t
conten .
e
in her
15
16. Components of AWS
Data in an S3 bucket are stored across a whole Region.
• Store
unlimited
objects
up
to
5TB
in
size.
• 99.999999999%
durability
and
99.99%
availability
of
objects
over
a
given
year.
• Cheap:
500GB
of
data
stored
in
S3
cost
about
$50/mo
to
store.
• Even
Twi,er’s
Vine
uses
S3
for
videos.
Note:
US
Standard
Region
==
Northern
Virginia
or
Pacific
Northwest
using
network
maps.
16
17. Components of AWS
The AWS Dashboard
ance
and Perform ring
C reate e o
Monit rts.
manag ers. le
serv and a
v i rtual
ve it
B ut ser ere
h
From
and
cheap e.
Dirt nkabl
Unsi ti c
Put all sta
t
conten .
e
in her
17
19. Components of AWS
The AWS Dashboard
and
ation ve
ance Clou dForm We will ha e…
and Perform ring init.
Cloud- to that next t
im
C reate e o
Monit rts.
manag ers. le to get
serv and a
v i rtual
,
Cheap cy,
ten pers
low la twork ther develo e.
r
ne
global DNS Give o access he s!
ve it AWS hare login
B ut ser ere. of
rs. s
From
h Serve Don’t
and
cheap e.
Dirt nkabl ed
Unsi l manag sage
ti c Usefu ike Mes
Put all sta es l PI.
t
conten . servic and Email A
in her
e Queue
and
ed DB’s Most
Manag ching.
ca
memory backup
19
autoscale and ly.
ical
automat
20. Components of AWS
EC2 Lingo
• EC2: Amazon Elastic Compute Cloud is virtual computing enviornment and
service that provides resizable computer capacity. Setup in minutes. Charged
by the hour while running.
• AMI: Amazon Machine Image is a special type of pre-configured operating
system which is used to create a Virtual Machine within EC2. You can start
with community run AMI’s and then make your own.
• EIP: Elastic IP Address is a static IP address you can assign to an EC2
instance so it has a none-changing semi-permanent address. They are free
but limited to 10. More potentially available on request to Amazon.
• Security Group: A virtual firewall to specify what ports are accessible on your
EC2 instance.
20
21. Components of AWS
EC2 Lingo
• EBS: Elastic Block Store is a persistent storage volume that can be attached
to any running EC2 instance.
– Sized from 1 GB to 1 TB.
– Must be placed in the same Availability Zone as the EC2 instance.
– Each storage volume is automatically replicated within the same Availability Zone.
– EC2 instance can have multiple EBS volumes but EBS can not be mounted on more
than one EC2 at time.
– Snapshots can be created from any EBS volume and stored in S3 to protect data or
to be used as a starting point for a new volume. Snapshots are incremental.
– Like regular hard drive you can attach multiple volumes and stripe your data across
them in a RAID configuration for increased I/O.
– You can also enable “provisioned IOPS” for higher performance for a cost.
21
22. Components of AWS
EC2 Lingo
• Instance Storage: Temporary storage that most EC2 instance get for free. If
the server reboots the data in Instant Storage stays but if the server is stopped
all Instance Storage data is lost. Good for temporary data only. Originated
before EBS existed, and only benefit over EBS is that it’s free.
22
23. Setting up Your First EC2 Instance
From the main Dashboard click “EC2”, then “Key Pair” at the bottom left.
23
24. Setting up Your First EC2 Instance
We want to use our existing SSH key so click “Import Key Pair”.
24
25. Setting up Your First EC2 Instance
Fill out a Keypair Name and then use terminal to paste your public ssh key.
1
mauvis1
4
3
paste
2
Create
a
new
SSH
key
if
you’ve
never
made
one
before:
25 h,ps://help.github.com/ar<cles/genera<ng-‐ssh-‐keys
26. Setting up Your First EC2 Instance
Your key pair is now created.
26
27. Setting up Your First EC2 Instance
Select “Instances” and then “Launch Instance”.
2
1
27
28. Setting up Your First EC2 Instance
Click “Continue” on the Classic Wizard.
1
28
29. Setting up Your First EC2 Instance
Select the Amazon Linux AMI.
29
30. Setting up Your First EC2 Instance
Note the “Instance Type” dropdown and “AZ”. For now go with defaults.
30
31. Setting up Your First EC2 Instance
Advance options screen. Go with defaults.
31
32. Setting up Your First EC2 Instance
You can add EBS or Instance Volumes here. Default is 8GB EBS.
32
33. Setting up Your First EC2 Instance
Give the server a name and Continue.
33
34. Setting up Your First EC2 Instance
Specify your Key Pair and Continue.
34
35. Setting up Your First EC2 Instance
Go with the default security group that allows SSH.
35
36. Setting up Your First EC2 Instance
Confirm all settings and click “Launch”.
36
37. Setting up Your First EC2 Instance
Close confirmation window.
37
38. Setting up Your First EC2 Instance
In about 2 minutes your new instance should be ready.
38
39. Setting up Your First EC2 Instance
SSH into the server to test that your key works. Default user is “ec2-user”.
One-time
confirmation
Success
You
could
also
have
create
the
same
instance
by
command-‐line:
39
ec2-run-instances -t t1.micro -g quick-start-1 ami-54cf5c3d -v –key "mauvis1"
40. A complete sample web app architecture
Coming in part 2: Load balancing across Availability Zones
40
From:
h,p://media.amazonwebservices.com/architecturecenter/AWS_ac_ra_web_01.pdf