I. Introduction

  1. EC2 is the backbone of AWS and encompasses a bundle of services, mainly

    1. Renting virtual machines
    2. Storing data on virtual drives (EBS)
    3. Distributing load across machines (ELB)
    4. Scaling the services using an auto scaling group (ASG)
  2. By default, an instance comes with

    1. Private IP for internal AWS network
    2. Public IP for WWW
  3. EC2 instances can run scripts on startup based on User Data.

  4. As per SLA, EC2 guarantees a monthly uptime of at least 99.99% with EBS in a region.

  5. Offers variety of CPU options including AMD (x86), Intel (x86), ARM etc.

  6. Loosely based on Linux KVM.

  7. You can query the metadata (instance ID, network interface) by

    1. Run the command $ curl[<http://169.254.169.254/latest/meta-data/>](<http://169.254.169.254/latest/meta-data/>)
    2. Download and run the Instance Metadata Query Tool

II. Launch Types

  1. On demand: short workload, predictable pricing

    1. Pay for what you use
    2. Has the highest cost but no upfront payment
    3. No long term commitment
    4. Perfect for "elastic" load
    5. Analogy: Coming and staying in hotel whenever you want but pay full price.
  2. Reserved (min 1 year)

    1. Reserved Instance: long workloads

    2. Convertible Reserved Instance

      1. Long workloads with flexible instances aka change configuration during the lifecycle
      2. Only Convertible Reserved Instances can be exchanged for other Convertible Reserved Instances
    3. Scheduled Reserved Instance — every Thursday, 3p-6p

    4. Up to 75% cheaper, pay upfront for 1-3 year period

    5. Suitable for traditional IT uses

    6. To take advantage of capacity reservation, you should buy RI in a specific AZ (zonal RI)

    7. You can purchase RI for an already running instance

    8. You can sell your RIs to other customers on AWS Marketplace if no longer needed

    9. Analogy: Planning and booking way ahead of time to get a discount.

  3. Spot: short workloads, cheap but unreliable

    1. Spare instances with up to 90% savings than on-demand
    2. Can gracefully recover from instance failures!
    3. Can be interrupted with 2-min notification. You can choose to either stop, terminate or hibernate your spot instance on termination. Default is termination.
    4. Can request as many as the region allows
    5. Useful for workloads resilient to failure e.g. batch jobs, image processing
    6. Not great for critical jobs like databases
    7. Define max_spot_price and get the instance while current_spot_price < max_spot_price
    8. The hourly price varies based on offer and capacity
    9. When your bid is no longer the highest, you get a 2-min window to either stop or terminate the instance (you will be billed closes to a second)
    10. Should have enough RAM (EBS root volume) if you wish to hibernate
    11. You can either request it "once" or "persistent"
    12. Cannot use with third-party AMI but only AWS/MS/Linux AMIs
    13. Only available for C, M and R classes
    14. To cancel instances, make sure you cancel request first otherwise it will be an infinite loop where the request will be invoked to re-create the stopped/terminated instance
    15. Analogy: Hotel allows bidding for empty rooms and highest bidder wins. You can be kicked out at any time.
    16. Spot Block allows you to request spot instances for specified duration from 1 to 6 hours. These instances are guaranteed to run without interruption for block duration requested. It offers 30 to 50% discount over on-demand pricing
  4. Spot fleets = set of spot instances + (optional) on-demand instances

    1. Allows us to automatically request spot instances with the lowest price
    2. Tries best to meet target capacity with price constraints
    3. Supports multi-AZ fleets but NOT multi-region
    4. It first creates candidate pools (size, OS, AZ) and then picks the best candidate
    5. Strategies to allocate spot pools
      1. Lowest price: candidate with lowest price
      2. Diversified: distributed across all pools (great availability for longer workloads)
      3. Capacity optimized: Pool with optimal capacity for number of instances
  5. EC2 fleet = same as Spot fleet, don't migrate

    1. Does not support multi-region fleet reservation
    2. Can modify the fleet in "maintenance" mode
  6. Dedicated instances: No other customer will share your hardware

    1. Run in a VPC on hardware that’s dedicated to a single customer.
    2. Your Dedicated instances are physically isolated at the host hardware level from instances that belong to other AWS accounts.
    3. May share hardware with other instances in the same account
    4. Automatic instance placement and billing is per instance.
  7. Dedicated hosts: book an entire physical server

    1. Expensive
    2. Visibility into the underlying sockets and physical cores of hardware
    3. Full control over instance placement
    4. Suitable for BYOL scenarios
    5. Billing is on a per-host basis (and not per instance)
    6. Analogy: Book an entire building of hotel.
  8. Best combo: Reserved for baseline + On-demand/Spot for spikes

III. Instant Types