Sub topic 18
Purchasing Options and Controlling Cost
This chapter assumes you can launch and stop instances with the AWS CLI, know the instance families from the earlier chapter, and understand that EC2 bills per instance-second (minimum 60 seconds) for Linux instances. It covers how you pay for compute, what else shows up on the bill, and the checks that stop surprises.
What you pay for
The instance price is only one line item. For a typical instance, charges come from these sources:
| Charge | When it applies | Stops when |
|---|---|---|
| Compute | While the instance is in the `running` state | Instance is stopped or terminated |
| EBS volumes | While the volume exists, attached or not | Volume is deleted |
| EBS snapshots | While the snapshot exists | Snapshot is deleted |
| Public IPv4 addresses | Per hour for every public IPv4 address, whether auto-assigned or Elastic | Address is released or the instance is terminated |
| Data transfer | Outbound to the internet and across some Regions or AZs | Traffic stops |
A stopped instance costs nothing for compute, but its EBS volumes still bill. This is the most common cause of "I turned everything off and still got a bill."
The four purchasing options
All four options run the same hardware and the same instance types. They differ in price, commitment, and whether AWS can take the capacity back.
On-Demand
You pay the published hourly rate with no commitment. You can launch and terminate at any time. This is the default for run-instances, and it is the right choice for new workloads whose usage you cannot yet predict, short experiments, and anything you may delete next week.
Savings Plans
A Savings Plan is a commitment to spend a fixed dollar amount per hour (for example, 0.10 USD per hour) for one or three years. In return, usage covered by the plan is billed at a lower rate. Usage above the commitment is billed at On-Demand rates.
There are two main kinds:
- Compute Savings Plans apply across instance families, sizes, Regions, and operating systems. They also cover Fargate and Lambda. They give the most flexibility and a smaller discount.
- EC2 Instance Savings Plans are tied to one instance family in one Region (for example,
m6iinus-east-1). They give a larger discount but less flexibility. Size and operating system within the family can still change.
You pay the commitment every hour, even if your usage drops below it. The risk is over-committing.
Reserved Instances
A Reserved Instance (RI) is an older billing discount for a specific instance configuration, again for one or three years. Standard RIs give the larger discount and fix the family. Convertible RIs let you exchange for different attributes at a smaller discount. RIs can optionally reserve capacity in an Availability Zone. For most new purchases, Savings Plans cover the same need with less bookkeeping, but existing RIs keep working and are still common in older accounts.
Spot Instances
Spot Instances use spare EC2 capacity at a steep discount compared with On-Demand. The catch: AWS can reclaim the capacity, and it sends a two-minute interruption notice first. Your workload must tolerate being stopped at any time.
Good fits are batch jobs, CI workers, data processing, rendering, and stateless web tiers behind a load balancer. Poor fits are databases with a single copy of the data, and anything that cannot checkpoint its progress.
You request Spot capacity by adding market options to run-instances:
aws ec2 run-instances \
--image-id "$AMI_ID" \
--instance-type t3.micro \
--subnet-id subnet-0123456789abcdef0 \
--security-group-ids sg-0123456789abcdef0 \
--instance-market-options 'MarketType=spot,SpotOptions={SpotInstanceType=one-time,InstanceInterruptionBehavior=terminate}' \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=tutorial-spot}]'Spot capacity differs by instance type and Availability Zone. Flexibility helps: if you can run on several instance types and AZs, you are interrupted less often. Auto Scaling groups with mixed instance policies are the usual way to do this.
On the instance, you can check for a pending interruption through the metadata service, using the IMDSv2 token flow from the metadata chapter:
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" \
-H "X-aws-ec2-metadata-token-ttl-seconds: 300")
curl -s -H "X-aws-ec2-metadata-token: $TOKEN" \
http://169.254.169.254/latest/meta-data/spot/instance-actionThe request returns an HTTP 404 while no interruption is planned. When one is planned, it returns JSON with the action and the time.
Comparing the options
| Option | Commitment | Discount level | Can AWS interrupt you? | Best for |
|---|---|---|---|---|
| On-Demand | None | None | No | Unpredictable or short-lived work |
| Savings Plan | 1 or 3 years of hourly spend | Moderate to large | No | Steady baseline usage |
| Reserved Instance | 1 or 3 years, specific configuration | Moderate to large | No | Existing fixed configurations |
| Spot | None | Largest | Yes, with two minutes' notice | Fault-tolerant, flexible work |
A common pattern combines them. Cover the always-on baseline with a Savings Plan, handle spikes with On-Demand, and run interruptible background work on Spot.
Controlling cost in practice
Choosing a purchasing option saves money only after you stop paying for things you do not need. These habits matter more than the discount tier.
- Right-size. Look at CloudWatch CPU and memory trends (memory needs the CloudWatch agent). An instance averaging 5 percent CPU can usually move to a smaller size. AWS Compute Optimizer produces recommendations from the same data.
- Stop what you are not using. Development and test instances rarely need to run overnight. Remember that attached EBS volumes continue to bill.
- Tag everything. The
Nametag from the launch chapter is a start. Add tags such asProjectandOwner, then activate them as cost allocation tags in the Billing console so Cost Explorer can group spend by them. - Set alerts before you need them. Create an AWS Budget with an email alert at a threshold such as 80 percent of your monthly target.
- Clean up orphans. Look for unattached volumes, old snapshots, and unused Elastic IPs.
This command lists volumes in the available state, meaning they are not attached to any instance but still cost money:
aws ec2 describe-volumes \
--filters Name=status,Values=available \
--query 'Volumes[].[VolumeId,Size,CreateTime]' \
--output tableTo see recent spend by service from the CLI, query Cost Explorer. The date range below is an example and the end date is exclusive:
aws ce get-cost-and-usage \
--time-period Start=2026-11-01,End=2026-11-26 \
--granularity MONTHLY \
--metrics UnblendedCost \
--group-by Type=DIMENSION,Key=SERVICECost Explorer data can lag by up to a day, and the API itself has a small per-request charge.
Common mistakes
- Buying a commitment too early. Commit after you have a few weeks of steady usage data, and start with a portion of your baseline rather than all of it.
- Assuming Spot is always available. A Spot request can fail for lack of capacity. Build in a fallback to On-Demand.
- Forgetting the free tier ends. Free tier allowances apply for a limited period, and they do not cover every resource, such as public IPv4 addresses on every account type. Check your account's current terms.
- Ignoring data transfer. Traffic between Availability Zones and out to the internet is billed. Putting chatty components in the same AZ can reduce cost, at some availability trade-off.
- Leaving Elastic IPs unattached. All public IPv4 addresses bill hourly, so release any you no longer use.
Exercise
A team runs a web server 24 hours a day that has had steady load for six months. They also run a nightly report job that can be restarted from the beginning if it fails. Which purchasing option fits each workload, and why?
Show answer
The web server fits a Savings Plan (or a Reserved Instance), because its usage is steady and predictable and it cannot be interrupted, so a one-year or three-year commitment lowers the rate. The nightly report job fits Spot Instances, because it can restart from the beginning, so an interruption costs only some repeated work while the discount is the largest available.
Exercise
You stopped an instance yesterday to save money, but the bill still shows EC2-related charges. Name two likely causes and one CLI command that helps find one of them.
Show answer
The instance's EBS volumes still bill while stopped, and an Elastic IP or other public IPv4 address still bills hourly. Running aws ec2 describe-volumes --filters Name=status,Values=available lists volumes not attached to any instance, and aws ec2 describe-addresses lists Elastic IPs so you can release unused ones.