Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Scaling your Web App on the Cloud with AWS (for frontend developers) Part 1

Intro to Scaling your Web App on the Cloud with AWS (for frontend developers) Part 1

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.

Mauvis Ledford

April 02, 2013
Tweet

More Decks by Mauvis Ledford

Other Decks in Technology

Transcript

  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 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 What we’re going to cover
  4. Server and Network Basics •  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 The Lingo
  5. Server and Network Basics •  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. 5 The Lingo •  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. Image  from:  h,p://www.y-­‐tech.net/userfiles/image/Hos<ng/vps.jpg  
  6. Virtualization and the Cloud 6 The problem of unpredictable usage

    From:  h,p://media.amazonwebservices.com/AWS_TCO_Web_Applica<ons.pdf  
  7. Virtualization and the Cloud 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 Why is virtualization such a big deal?
  8. Why Amazon Cloud? •  Reputation: Biggest and most well- known

    cloud provider. 8 Why we chose AWS •  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.
  9. Why Amazon Cloud? •  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 Why we chose AWS
  10. The Cloud Philosophy •  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 Fast and nimble Image  from:  h,p://minibeasts-­‐bees.wikispaces.com/Images+%26+You+Tube+clips+of+bees  
  11. Components of AWS 11 •  A Region is essentially a

    cluster of “Availability Zones”. •  Edge Locations are for Cloudfront CDN. This is the Cloud: 9 Regions worldwide, 4 in North America
  12. Components of AWS 12 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. From:  h,p://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-­‐regions-­‐availability-­‐zones.html   •  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.
  13. Components of AWS 13 The AWS Dashboard Create and manage

    virtual servers. Performance Monitoring and alerts.
  14. Components of AWS 14 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. Using Cloudwatch metrics
  15. Components of AWS 15 The AWS Dashboard Create and manage

    virtual servers. Dirt cheap and Unsinkable. Put all static content in here. Performance Monitoring and alerts.
  16. Components of AWS 16 Data in an S3 bucket are

    stored across a whole Region. Note:  US  Standard  Region  ==  Northern  Virginia  or  Pacific  Northwest  using  network   maps.   •  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.  
  17. Components of AWS 17 The AWS Dashboard Create and manage

    virtual servers. Dirt cheap and Unsinkable. Put all static content in here. But serve it From here Performance Monitoring and alerts.
  18. Components of AWS 19 The AWS Dashboard Create and manage

    virtual servers. Dirt cheap and Unsinkable. Put all static content in here. Performance Monitoring and alerts. But serve it From here. Cheap, low latency, global network of DNS Servers. Give other developers AWS access here. Don’t share logins! Managed DB’s and memory caching. Most autoscale and backup automatically. Useful managed services like Message Queue and Email API. CloudFormation and Cloud-init. We will have to get to that next time…
  19. Components of AWS •  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 EC2 Lingo
  20. Components of AWS •  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 EC2 Lingo
  21. Components of AWS •  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 EC2 Lingo
  22. Setting up Your First EC2 Instance 23 From the main

    Dashboard click “EC2”, then “Key Pair” at the bottom left.
  23. Setting up Your First EC2 Instance 24 We want to

    use our existing SSH key so click “Import Key Pair”.
  24. Setting up Your First EC2 Instance 25 Fill out a

    Keypair Name and then use terminal to paste your public ssh key. 2   3  paste   Create  a  new  SSH  key  if  you’ve  never  made  one  before:   h,ps://help.github.com/ar<cles/genera<ng-­‐ssh-­‐keys   4   mauvis1   1  
  25. Setting up Your First EC2 Instance 30 Note the “Instance

    Type” dropdown and “AZ”. For now go with defaults.
  26. Setting up Your First EC2 Instance 32 You can add

    EBS or Instance Volumes here. Default is 8GB EBS.
  27. Setting up Your First EC2 Instance 35 Go with the

    default security group that allows SSH.
  28. Setting up Your First EC2 Instance 38 In about 2

    minutes your new instance should be ready.
  29. Setting up Your First EC2 Instance 39 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:    ec2-run-instances -t t1.micro -g quick-start-1 ami-54cf5c3d -v –key "mauvis1"
  30. A complete sample web app architecture 40 Coming in part

    2: Load balancing across Availability Zones From:  h,p://media.amazonwebservices.com/architecturecenter/AWS_ac_ra_web_01.pdf  
  31. Additional Reading •  Amazon Architecture Center: Amazon Architecture Center: http://aws.amazon.com/architecture/

    •  Best Practices Whitepaper: http://media.amazonwebservices.com/AWS_Cloud_Best_Practices.pdf •  Operation checklist: http://media.amazonwebservices.com/AWS_Operational_Checklists.pdf •  Whitepaper on Autoscale: http://aws.amazon.com/autoscaling/ •  The Reddit AWS community: http://www.reddit.com/r/aws/ •  Mauvis’s Amazon EC2 Pricing Calculator Google Doc: http://goo.gl/Er90C 41