Skip to content

Latest commit

 

History

History
159 lines (144 loc) · 7.63 KB

File metadata and controls

159 lines (144 loc) · 7.63 KB

EC2: Virtual Machines

By default, your EC2 machine comes with:

  • A private IP for the internal AWS Network
  • A public IP for the WWW

When you SSH into your EC2 machine:

  • We can’t use a private IP, because we are not in the same network
  • We can only use the public IP

If your machine is stopped and then restarted, the public IP will change

EC2 User Data

  • It is possible to bootstrap our instances using an EC2 User data script
  • Bootstrapping means launching commands when a machine starts
  • That script is only run once at the instance first start
  • Purpose: Ec2 data is used to automated boot tasks such as:
    • Installing updates
    • Installing software
    • Downloading common files from the internet
  • The EC2 User Data Script runs with the root user

EC2 Meta Data

  • Information about your EC2 instance
  • It allows EC2 instances to "learn" about themselves without having to use an IAM role for that purpose
  • Powerful but one of the least known features to developers
  • You can retrieve IAM roles from the metadata but not IAM policies
  • URL: {ec2-ip-address}/latest/meta-data

EC2 Instance Launch Types

  • On Demand Instances: short workload, predictable pricing
  • Reserved Instances: long workloads (>= 1 year)
  • Convertible Reserved Instances: long workloads with flexible instances
  • Scheduled Reserved Instances: launch within time window you reserve
  • Spot Instances: short workloads, for cheap, can lose instances
  • Dedicated Instances: no other customers will share your hardware
  • Dedicated Hosts: book an entire physical server, control instance placement

On Demand Instance:

  • Pay for what you use
  • Has the highest cost but no upfront payment
  • No long term commitment
  • Recommended for short-term and un-interrupted workloads, where you can’t predict how the application will behave

Reserved Instances

  • Up to 75% compared to On-demand
  • Pay upfront for what you use with long term commitment
  • Reservation period can be 1 or 3 years
  • Reserve a specific instance type
  • Recommended for steady state usage applications (think database)

Convertible Reserved Instances

  • Can change the EC2 instance type
  • Up to 54% discount

Scheduled Reserved Instances

  • Launch within time window you reserve
  • When you require a fraction of a day / week / month

Spot Instances

  • Can get a discount of up to 90% compared to On-demand
  • You bid a price and get the instance as long as it's under the price
  • Price varies based on offer and demand
  • Spot instances are reclaimed within a 2-minute notification warning when the spot price goes above your bid
  • Used for batch jobs, Big Data analysis, or workloads that are resilient to failures
  • Not great for critical jobs or databases

Dedicated Instances

  • Instances running on hardware that’s dedicated to you
  • May share hardware with other instances in same account
  • No control over instance placement (can move hardware after stop / start)

Dedicated Hosts

  • Physical dedicated Ec2 server for your use
  • Full control of Ec2 Instance placement
  • Visibility into the underlying sockets / physical cores of the hardware
  • Allocated for your account for a 3-year period reservation
  • More expensive
  • Useful for software that have a complicated licensing model (Bring your own License)
  • Or for a companies that have strong regulatory or compliance needs

Which host is right for me?

  • On demand: coming and staying in resort whenever we like, we pay the full price
  • Reserved: like planning ahead and if we plan to stay for a long time, we may get a good discount.
  • Spot instances: the hotel allows people to bid for the empty rooms and the highest bidder keeps the rooms.You can get kicked out at any time
  • Dedicated Hosts: We book an entire building of the resort

EC2 Pricing

  • EC2 instances prices (per hour) varies based on these parameters:

    • Region you’re in
    • Instance Type you’re using
    • On-Demand vs Spot vs Reserved vs Dedicated Host
    • Linux vs Windows vs Private OS (RHEL, SLES, Windows SQL)
    • You are billed by the second, with a minimum of 60 seconds.
    • You also pay for other factors such as storage, data transfer, fixed IP public addresses, load balancing
    • You do not pay for the instance if the instance is stopped
  • Example

    • t2.small in US-EAST-1 (VIRGINIA), cost $0.023 per Hour
    • If used for:
      • 6 seconds, it costs $0.023/60 = $0.000383 (minimum of 60 seconds)
      • 60 seconds, it costs $0.023/60 = $0.000383 (minimum of 60 seconds)
      • 30 minutes, it costs $0.023/2 = $0.0115
      • 1 month, it costs $0.023 * 24 * 30 = $16.56 (assuming a month is 30 days)
      • X seconds (X > 60), it costs $0.023 * X / 3600
    • The best way to know the pricing is to consult the pricing page: https://aws.amazon.com/ec2/pricing/on-demand/

AMIs

What's AMI?

  • As we saw, AWS comes with base images such as:
    • Ubuntu
    • Fedora
    • RedHat
    • Windows
    • Etc...
  • These images can be customized at runtime using EC2 User data
  • But what if we could create our own image, ready to go?
  • That’s an AMI – an image to use to create our instances
  • AMIs can be built for Linux or Windows machines

Why you use a custom AMI?

  • Using a custom-built AMI can provide the following advantages:
    • Pre-installed packages needed
    • Faster boot time (no need for long ec2 user data at boot time
    • Machine comes configured with monitoring / enterprise software
    • Security concerns – control over the machines in the network
    • Control of maintenance and updates of AMIs over time
    • Active Directory Integration out of the box
    • Installing your app ahead of time (for faster deploys when auto-scaling)
    • Using someone else’s AMI that is optimized for running an app, DB, etc...
  • AMI are built for a specific AWS region (!)

EC2 Instances Overview

  • Instances have 5 distinct characteristics advertised on the website:
    • The RAM(type,amount,generation)
    • The CPU(type,make,frequency,generation,numberofcores)
    • The I/O (disk performance, EBS optimisations)
    • The Network (network bandwidth, network latency
    • The Graphical Processing Unit (GPU)
  • It may be daunting to choose the right instance type (there are over 50 of them) - https://aws.amazon.com/ec2/instance-types/
  • https://ec2instances.info/ can help with summarizing the types of instances
  • R/C/P/G/H/X/I/F/Z/CR are specialised in RAM, CPU, I/O, Network, GPU
  • M instance types are balanced
  • T2/T3 instance types are “burstable” Burstable Instances (T2)
  • AWS has the concept of burstable instances (T2 machines)
  • Burst means that overall, the instance has OK CPU performance.
  • When the machine needs to process something unexpected (a spike in load for example), it can burst, and CPU can be VERY good.
  • If the machine bursts, it utilizes “burst credits”
  • If all the credits are gone, the CPU becomes BAD
  • If the machine stops bursting, credits are accumulated over time
  • Burstable instances can be amazing to handle unexpected traffic and getting the insurance that it will be handled correctly
  • If your instance consistently runs low on credit, you need to move to a different kind of non-burstable instance (all the ones described before).

T2 Unlimited

  • Nov 2017: It is possible to have an “unlimited burst credit balance
  • You pay extra money if you go over your credit balance, but you don’t lose in performance
  • Overall, it is a new offering, so be careful, costs could go high if you’re not monitoring the health of your instances