Tyler Sengia

Unit 5: Amazon EC2 + EBS

Study notes for Amazon EC2 and EBS.

EC2 is one of Amazon’s foundational services, and is one of the oldest available.

As such, there are many, many different features.

There are also many different ways for costs to explode (also as is the case for networking on AWS).

AMIs and Virtualization

Amazon Machine Images (AMIs) are templates for EC2 instances. They define the following:

  1. An image of the root volume (ie. OS) of the instance
  2. Block device mapping
  3. Controls over who can access the AMI to launch instances

AMIs also define the type of virtualization that the EC2 instance will use. There are two possible virtualization types:

  • Hardware Virtual Machine (HVM)
  • Para-virtualization (PV)

From the AWS docs, it seems like HVM is the solid winner here and PV is a legacy tech to migrate away from.

Hypervisors

By default when you create a t2.micro instance, it is not tiny dedicated computer like a tiny Raspberry Pi, but is instead a tiny virtualized slice of resource from a massive server. This massive server uses a hypervisor to divide up the hardware resources among the instances on the host according to the instance sizes.

There are two main hypervisors used at Amazon:

  • Intel Xen
  • AWS Nitro

AWS Nitro is newer, and has support for Nitro Security Enclaves.

Storage Options

All EC2 instances must have a root volume, which contains the OS/image for the instance.

Typically, this would be an EBS volume, but if you’re using a Linux instance, you can use an instance store instead.

Instance stores are physical block devices that provide ephemeral storage. This means data written to instance stores do not persist when the instance is stopped/terminated/rebooted. Fewer instance types support instance store root volumes, see here. Non-root instance stores are common in EC2 instance types.

Although instance stores are not persistent, they are still useful due to being far cheaper than EBS. Examples include storing cache data, certain logs, and temporary output files. Someone on the internet also used instance stores and DB replication to reduce the cost of running an SQL server.

Besides instance stores and EBS volumes, you can also mount EFS and FSx networked file systems on Linux instances to provide a networked, shared filesystem between instances.

Purchasing Options

Pay attention here. EC2 costs will steal your money if you let it. But there are ways to save if you’re smart.

Typically, users tend to go with On-Demand instances. They’re easy to start, stop, scale and you only pay for what you use.

Pretty great at first, and great for short lived tutorials and learning, but not great for long-term business use cases.

Instead, there are other options to get compute capability and pay less than On-Demand costs.

Many of these options can be combined together to make capability more affordable.

If you plan on using compute power for a long time (ie. at least 1 year), then sign up for an Compute Savings Plan, which can save you up to 72% off the On-Demand cost for the instance. The 72% off figure seems to be a maximum, and real savings may be in the 38% to 60% range according to this article by CloudZero.

Another option is to get an EC2 Reserved Instance. Reserved Instances also require a 1-3 year commitment, and offer similar discounts, however you can sell your reserved instances on the AWS RI Marketplace if it is unutilized. Reserved Instances also can reserve capacity for you as well, which ensures that you workloads always has computer power available.

If you don’t go with Reserved Instances and still need to guarantee compute availability, you can purchase an EC2 Capacity Reservation. It’s a good idea to reserve compute capacity. There have been many cases of workloads being unable to scale to meet peak demand because all the compute capacity was used up! AWS is not a limitless supply of compute power, it has a limit which has been exceeded in the past.

For some workloads, you are required to ensure that your software is running on a single-tenant host (ie. no-one else is sharing the physical hardware with you). This would require you to use Dedicated Hosts and Dedicated Instances. Dedicated Hosts can be expensive; after all, you’re renting out an entire computer from AWS, who would typically divide it up upon dozens of customers. However, if you commit to a Dedicated Host Reservation you could save 35% to 45% off On-Demand pricing.

Finally, make sure that you actually need EC2 instances running for long periods of time. Many workloads, such as hosting a website, RESTful APIs, and serving static content is better offloaded to AWS Lambda, S3, and CloudFront instead of having an EC2 instance running 24/7. It may also be helpful to use Spot Instances for background/optional processing, which can give you an even larger discount.

This guide only serves to connect ideas already presented in AWS documentation to provide a more complete learning path. After reading this, you should take the time to read these resources as well:

Anki Deck

AWS EC2 + EBS Anki Deck