Sub topic 3
Reserved Instances: how they work
This chapter assumes you know what EC2 instances, instance families, Regions, and Availability Zones are. It also assumes you have seen an EC2 bill that charges per instance-hour.
What a Reserved Instance is
A Reserved Instance (RI) is not a separate machine. It is a billing discount that you buy for a one-year or three-year term. You commit to a specific instance configuration, and AWS lowers the hourly price of matching usage.
You launch instances the normal way. At the end of each hour, billing checks whether a running instance matches one of your RIs. If it does, you pay the reduced RI rate for that hour. If it doesn't, you pay the On-Demand rate.
An RI reserves a price, not an instance. Terminating an instance does not cancel the RI. The RI keeps billing for its whole term, whether or not anything matches it.
What an RI matches
An RI is defined by these attributes:
- Instance type, such as
m5.large. - Platform, such as Linux/UNIX or Windows.
- Tenancy, which is default (shared hardware) or dedicated.
- Scope, which is a Region or a single Availability Zone.
Billing applies the RI to usage that matches these attributes. Regional RIs also apply across sizes within the same instance family, using size-flexibility rules. For example, one m5.xlarge RI can cover two m5.large instances. Chapter sections later in this tutorial cover scope in detail.
How billing applies an RI
Suppose you hold one Linux m5.large RI in a Region. Over one hour, you run three m5.large Linux instances.
- Billing matches the RI to one of the three instances.
- That instance is billed at the RI rate.
- The other two instances are billed at On-Demand rates.
If you run only one such instance, the RI covers it. If you run none, you still pay for the RI, and that hour is unused reservation.
Seeing your reservations
You can list your RIs with the AWS CLI:
aws ec2 describe-reserved-instances \
--filters Name=state,Values=active \
--query 'ReservedInstances[].[ReservedInstancesId,InstanceType,InstanceCount,End]' \
--output tableThe output shows each active RI, its instance type, how many it covers, and when it expires. Compare InstanceCount with what you actually run. If you hold more RIs than you run matching instances, you are paying for unused reservations.
Common errors
- Buying without checking usage. RIs pay off only when matching instances run for most of the term. Check your steady usage before you buy.
- Mismatched attributes. An RI for Linux does not discount a Windows instance. A zonal RI for
us-east-1adoes not discount an instance inus-east-1b. - Assuming the RI follows an instance. The discount follows matching usage in the account, not a particular instance ID.
- Forgetting expiry. When a term ends, matching usage returns to On-Demand rates with no warning in your bill beyond the price change.
- Treating RIs as a spending cap. RIs lower the rate for matching usage only. Extra usage is still charged On-Demand.
Exercise
You hold two Linux c5.large Regional RIs. In one hour you run three Linux c5.large instances and one Windows c5.large instance. How many instances are billed at the RI rate, and how many at the On-Demand rate?
Show answer
Two instances are billed at the RI rate, because each RI covers one matching Linux c5.large. The third Linux instance and the Windows instance (which does not match the platform) are billed at On-Demand rates, so two are billed On-Demand.