Skip to content
Certification Guide

Task 4.2 · 23 min read

Cost-Optimized Compute

Services in this lesson

  • Amazon EC2in scope
  • Amazon EC2 Auto Scalingin scope
  • Savings Plansin scope
  • AWS Compute Optimizerin scope
  • AWS Lambdain scope
  • AWS Fargatein scope
  • Amazon ECSin scope
  • AWS Cost Explorerin scope
  • AWS Budgetsin scope
  • AWS Cost and Usage Reportin scope
  • AWS Outpostsin scope

What the exam tests

  • Matching each part of a workload to the right purchase option: On-Demand, Compute or EC2 Instance Savings Plans, Standard or Convertible Reserved Instances, Spot Instances, Capacity Reservations and Dedicated Hosts.
  • Rightsizing before committing: reading AWS Compute Optimizer and AWS Cost Explorer recommendations, and picking a smaller size, a different family or a Graviton type when utilization says so.
  • Scaling for cost: an Auto Scaling group that mixes an On-Demand base with Spot, scheduled scale-in for non-production, hibernation for slow-starting instances, and different availability targets for production and non-production.
  • Choosing the cheapest compute model for the load shape. AWS Lambda suits spiky or idle-most-of-the-time work, and AWS Fargate (and Fargate Spot) suits teams that don't want to manage hosts. Amazon EC2 with commitments suits steady high utilization.
  • Watching commitments with AWS Cost Explorer, AWS Budgets and the AWS Cost and Usage Report, and sharing discounts across an organization.

The core concept

Compute cost comes down to two moves, in this order. First, stop paying for capacity you don't use. Second, buy the capacity you do use at the right price.

Stopping waste means rightsizing, turning off idle and non-production resources, and scaling with demand. Buying well means committing to the steady baseline, putting interruptible work on Spot, and leaving only the unpredictable rest on On-Demand.

An analogy: paying for your commute

Picture someone who commutes by bus and train. First they count how many trips they really take, so they don't buy a pass for trips they never make.

Then they pick a fare for each kind of trip. A single ticket costs the most but needs no promise. A monthly pass valid on every line is cheaper, and a pass for one route only is cheaper still.

For trips that can wait, they ride on standby: deep discounts, but they can be bumped off with little warning.

Where it breaks: an unused pass can often be refunded. A Savings Plan (a promise to spend a fixed amount per hour for 1 or 3 years) can be returned only in a short window right after purchase. After that you pay for every hour of its term, used or not.

Walk one fleet through it

The diagram reads top to bottom. Rightsize first. Then ask three questions: can it be interrupted, is it steady, must capacity be guaranteed?

Enlarge
Rightsize, then pick the purchase option from interruptibility, steadiness and flexibility.

Saltmarsh Games runs the servers behind an online multiplayer game. Mikael runs its AWS platform, and Yara leads finance and signs off every commitment.

  1. Yara wants a 3-year commitment for today's fleet. Mikael says no, not yet. Commit before rightsizing and you lock in waste for one or three years.
  2. Mikael opts in to AWS Compute Optimizer. It reads Amazon CloudWatch metrics (the AWS monitoring data) and recommends better sizes.
    • It flags the match servers at 10 percent CPU and suggests a smaller size.
    • It only sees memory because Mikael installed the CloudWatch agent, a program that publishes memory use from inside each instance.
  3. Mikael moves to Graviton. AWS Graviton is AWS's own Arm-based processor, and its instance types run arm64 code. The game server builds for Arm, so price performance usually improves.
  4. Next, the diagram asks: can the work be interrupted? Replay rendering and nightly test builds can restart from a checkpoint. Mikael puts them on Spot Instances, spare EC2 capacity at up to 90 percent off.
    • AWS can reclaim a Spot Instance with a two-minute warning, so only restartable work goes there.
  5. The match servers can't go on Spot. An interruption would drop live matches. They need a floor of instances that is always running.
  6. That floor is steady all year, so a Savings Plan discounts it. Yara buys a Compute Savings Plan sized to the floor. The floor still runs as ordinary instances, billed at the plan's lower rate.
    • Mikael plans to move some services to AWS Fargate, serverless container capacity. A Compute Savings Plan follows that move.
    • Short bursts above the floor stay on plain On-Demand, which bills by the second with no promise.
  7. A launch weekend needs guaranteed capacity in one Availability Zone. A Region is a geographic area of AWS. An Availability Zone (AZ) is one or more separate data centers inside a Region.
    • A Savings Plan never reserves capacity. Mikael books an On-Demand Capacity Reservation for the weekend, which holds EC2 capacity in one AZ for him.
    • The Savings Plan discounts the reservation, and he cancels it afterward.
  8. The test environment idles at night. It runs in an Auto Scaling group, a fleet that EC2 Auto Scaling grows and shrinks. A scheduled action, a capacity change at a set time, sets the group to zero every evening and back each morning.
  9. Yara watches the commitment. Cost Explorer is the billing console's tool for charting spend and usage. It shows whether the Savings Plan is fully used, and an AWS Budgets alert fires if use drops below her target.

Step 1 saved the most. Every later discount applied to a fleet that was already the right size.

The rules the exam tests

Commitments and capacity:

  • Rightsize first, commit second. A commitment sized to waste is billed every hour of its term.
  • On-Demand has no promise and no discount. Linux On-Demand bills by the second.
  • A Savings Plan commits to a USD amount per hour, for 1 or 3 years.
  • Compute Savings Plans give up to 66 percent off. They apply to any instance family (a group of instance types built for one kind of work), size and Region.
  • They also cover any operating system (OS) and tenancy (shared or single-tenant hardware). They discount Fargate and Lambda too.
  • EC2 Instance Savings Plans give up to 72 percent off. They are locked to one family in one Region but follow size, OS and tenancy changes.
  • No Savings Plan reserves capacity. It is a billing discount only.
  • Reserved Instances (RIs) are the older commitment model. Standard RIs can be sold but not exchanged. Convertible RIs can be exchanged but not sold.
  • A zonal RI (an RI tied to one AZ) reserves capacity there. A regional RI does not.
  • Guaranteed capacity without a long term is an On-Demand Capacity Reservation. Savings Plans still discount it.
  • Bringing per-socket or per-core server licenses means Dedicated Hosts. You get a whole physical server.
Deep diveCommitment details: returns, RIs and reservations

A Savings Plan can be returned only within its first seven days. The return must also fall in the same calendar month (UTC) it was bought.

Only a plan with an hourly commitment of $100 or less can be returned. A return refunds 100 percent of any upfront charges. After that window, the commitment is billed for the full term.

AWS now recommends Savings Plans over RIs. An RI commits to an instance configuration for 1 or 3 years.

A Standard RI gives up to 72 percent off, like EC2 Instance Savings Plans. It can be sold on the Reserved Instance Marketplace but not exchanged.

A Convertible RI gives up to 66 percent off, like Compute Savings Plans. It can be exchanged for a different family, OS or tenancy, but not sold.

A regional RI applies in any AZ of its Region. It is also size flexible within the family, for Linux with default tenancy. It does not reserve capacity.

A zonal RI reserves capacity in one AZ for one exact instance type.

A Capacity Reservation needs no long-term commitment. It can last any duration and can be cancelled.

It is billed at the On-Demand rate whether you use it or not. Savings Plans and regional RIs discount it.

Spot:

  • Spot Instances give up to 90 percent off On-Demand. AWS can reclaim them with two minutes' notice, and Spot capacity is never guaranteed.
  • Spot fits stateless, fault-tolerant, flexible work. Examples are batch jobs, CI/CD (continuous integration and delivery) builds, rendering, big data, containers and stateless web tiers behind a load balancer.
  • Keep stateful work off Spot. A database or a job that can't checkpoint can lose work or data when interrupted.
Deep diveMaking Spot reliable

Spot is reliable at scale only when you are flexible. Spread the group across many instance types and AZs.

A mixed instances group is an Auto Scaling group that combines On-Demand and Spot across several instance types. It keeps an On-Demand base and runs the rest on Spot.

An allocation strategy decides which Spot capacity pools the group launches into. A pool is one instance type in one AZ. Use price-capacity-optimized, which picks pools that are both cheap and least likely to be interrupted.

Turn on Capacity Rebalancing. Auto Scaling then replaces Spot Instances at risk of interruption before the two-minute notice arrives.

Rightsizing tools:

  • Compute Optimizer needs at least 30 hours of metrics before it recommends a size for an EC2 instance.
  • It sees memory only through the CloudWatch agent. EC2 doesn't publish memory metrics by default.
  • Cost Explorer recommends a Savings Plan size from your past usage. Compute Optimizer sizes resources, not commitments.
Deep diveCompute Optimizer and billing recommendations

Compute Optimizer works only after you opt in. It analyzes 14 days of CloudWatch metrics by default, or 93 days with paid enhanced infrastructure metrics.

It covers EC2 instances, Auto Scaling groups, Amazon EBS (Elastic Block Store) volumes, Lambda functions and Amazon ECS services on Fargate.

Without the CloudWatch agent or a supported observability tool, it can't see memory and may suggest a size that is too small. It never resizes anything itself.

Cost Explorer adds its own EC2 rightsizing recommendations. The Billing and Cost Management console shows the Savings Plans purchase recommendations.

The walkthrough switched off test capacity at night. Scaling and the compute model also decide what you pay.

Instance families and Auto Scaling policies are covered in task 3.2, compute performance. Lambda, Fargate, Amazon ECS and Amazon EKS basics are in task 2.1b, serverless and containers. Load balancer types are in task 2.1c.

Here the only question is which choice meets the requirement for the least money.

Scaling and hibernation

Non-production rarely needs to run at night. A scheduled action can set an Auto Scaling group's desired capacity to zero after hours and back in the morning. Stopped capacity costs nothing for instance usage.

Hibernation stops an instance but saves its RAM (memory) to the encrypted EBS root volume. A slow-starting application then resumes warm. You pay for the EBS storage, not for instance usage, while it is stopped.

Production keeps its Multi-AZ footprint (instances spread across several AZs) and its On-Demand or committed base. Non-production can trade availability for price with fewer instances, one AZ and Spot.

Deep diveHibernation prerequisites

Hibernation can be enabled only at launch. You can't turn it on for an instance that is already running.

The root volume must be an encrypted EBS volume. It must also be large enough to hold the instance's RAM.

Serverless and containers

Serverless and containers move the line between "idle" and "paid".

  • Lambda bills per request and for each invocation's duration at the memory you configure. A function idle most of the day costs almost nothing.
  • Compute Optimizer can recommend a Lambda function's memory size.
  • Lambda on arm64 typically gives better price performance.
  • Fargate bills the vCPU (virtual CPU) and memory a task requests while it runs. An oversized task definition is pure waste.
  • Fargate Spot runs interruption-tolerant ECS tasks at a discount. It gives the same two-minute warning as EC2 Spot.
  • Steady, busy, all-day work is usually cheapest on EC2 with a Savings Plan. Fargate removes host management, but it bills every requested vCPU for every hour.

Watching the bill

Cost Explorer shows Savings Plans and RI utilization: are you using what you bought? It also shows coverage: how much eligible usage is discounted?

AWS Budgets can alert when utilization or coverage drops below a target. The AWS Cost and Usage Report gives raw line-item detail. Task 4.1 covers cost allocation tags.

AWS Organizations groups accounts under one management account, and consolidated billing pays for them together. Discount sharing treats the organization as one account, so one central commitment discounts usage in every member account.

The management account can turn discount sharing off, for the whole organization or per account.

Decision guide

Terms used in the table below:

  • Capacity Reservation holds EC2 capacity in one AZ for you, at the On-Demand rate.
  • Mixed instances group is an Auto Scaling group that combines On-Demand and Spot across several instance types.
  • Scheduled action changes an Auto Scaling group's capacity at a set time.
Decision guide
If the question says…Reach for…Because…
steady 24/7 baseline, plans to change instance families, Regions or move to Fargate/LambdaCompute Savings PlansUp to 66 percent off, and the discount follows families, Regions, Fargate, Lambda
steady baseline on one instance family in one Region for 3 years, largest discountEC2 Instance Savings Plans (or Standard Reserved Instances)Up to 72 percent off. Size, OS and tenancy can still change within the family
commitment may need to be resold if the project ends earlyStandard Reserved InstancesOnly Standard RIs can be sold. A Savings Plan has only a short return window (see above)
batch, rendering, CI/CD or stateless workers that can restart; MOST cost-effectiveSpot Instances (or Fargate Spot for ECS tasks)Up to 90 percent off. Two minutes' notice suffices for work that checkpoints
web tier must keep a minimum running, extra capacity can be interruptedAuto Scaling mixed instances group: On-Demand base + Spot above itThe base stays On-Demand under a Savings Plan. The burst runs on many Spot pools
guaranteed capacity in one AZ for a two-week event, no long-term commitmentOn-Demand Capacity ReservationAny duration, cancellable, and Savings Plans still discount it
bring existing per-socket or per-core server licensesDedicated HostsA whole physical server, so per-socket, per-core or per-VM licenses work
instances run at 10 percent CPU; "rightsize" or "identify over-provisioned"AWS Compute Optimizer (install the CloudWatch agent for memory)Recommends smaller sizes or other families from 14 days of metrics. Memory needs the agent
dev and test environments idle nights and weekendsScheduled actions that set desired capacity to 0, then backStopped capacity costs nothing for instance usage. Production keeps its baseline
application takes 20 minutes to warm its in-memory cache after every startEC2 hibernation (enabled at launch, encrypted root volume)RAM is saved to EBS. You pay for storage only, and the app resumes warm
function runs a few seconds per request, idle most of the dayAWS Lambda (consider arm64)Billed per request and duration, nothing while idle. arm64 improves price performance
containers with no servers to manage, busy all day and every dayCompute Savings Plan (it covers Fargate), or EC2 under a commitment if utilization stays highFargate bills requested vCPU and memory every hour. Steady use is cheaper on committed EC2
Savings Plan bought last year, finance wants to know if it is fully usedCost Explorer utilization and coverage reports; AWS Budgets Savings Plans budgetUtilization shows unused commitment. A budget alerts when it drops below target

Correct pattern

REFERENCE PATTERN: an Auto Scaling group for a stateless web tier. It keeps two On-Demand instances as a floor, covered by a Savings Plan, and runs everything above the floor on Spot across several instance types and AZs.

{
  "AutoScalingGroupName": "web-tier",
  "MixedInstancesPolicy": {
    "LaunchTemplate": {
      "LaunchTemplateSpecification": {
        "LaunchTemplateName": "web-tier-template",
        "Version": "$Default"
      },
      "Overrides": [
        { "InstanceType": "m7g.large" },
        { "InstanceType": "m6g.large" },
        { "InstanceType": "c7g.xlarge" },
        { "InstanceType": "r7g.large" }
      ]
    },
    "InstancesDistribution": {
      "OnDemandBaseCapacity": 2,
      "OnDemandPercentageAboveBaseCapacity": 0,
      "SpotAllocationStrategy": "price-capacity-optimized"
    }
  },
  "CapacityRebalance": true,
  "MinSize": 2,
  "MaxSize": 20,
  "DesiredCapacity": 4,
  "VPCZoneIdentifier": "<subnet-az-a>,<subnet-az-b>,<subnet-az-c>"
}
aws autoscaling create-auto-scaling-group --cli-input-json file://web-tier.json

Why it holds up:

  • OnDemandBaseCapacity: 2 keeps a floor that Spot interruptions can't take away. That floor is the steady usage a Compute Savings Plan should cover.
  • OnDemandPercentageAboveBaseCapacity: 0 sends every instance above the floor to Spot. A less interruption-tolerant tier might use 50 instead.
  • Four instance types in three AZs give twelve Spot capacity pools. One reclaimed pool doesn't empty the group.
  • All four types are Graviton, so one arm64 AMI (Amazon Machine Image, the template that supplies an instance's operating system and software) works for all of them.
  • price-capacity-optimized chooses pools that are cheap and least likely to be interrupted. CapacityRebalance replaces at-risk Spot Instances before the two-minute notice.
  • Pair it with a scheduled action in the non-production copy of this group that sets desired capacity to 0 every evening.

Traps

TRAPExam traps
The trapWhy it failsCorrect pattern
Buy a 3-year Savings Plan for today's fleet, then rightsizeThe discount is immediate, but shrinking the fleet later leaves unused commitment you still pay forRightsize with Compute Optimizer first, then commit to the new steady baseline. After the short return window, every hour is billed
Run the whole production web tier, including its minimum, on SpotSpot is the biggest discount, but it can be reclaimed, so the tier can drop below its minimumOn-Demand base capacity for the minimum, Spot above it, many instance types and AZs
Use Spot for a stateful database or a job that can't checkpointLooks cheapest, but a two-minute interruption can lose work or dataSavings Plan or RI-covered On-Demand for stateful work; Spot only for work that can be interrupted and restarted
Expect a Savings Plan to guarantee capacity in an AZSavings Plans are a billing discount only. They never reserve capacityAdd an On-Demand Capacity Reservation (the Savings Plan discounts it), or buy a zonal RI
Choose EC2 Instance Savings Plans when the stem says the team will move to Fargate or another RegionBigger headline discount, but locked to one family in one Region. It never applies to Fargate or LambdaCompute Savings Plans whenever family, Region or compute service may change
Plan to sell an unneeded Convertible RI on the Reserved Instance MarketplaceOnly Standard RIs can be sold thereExchange the Convertible RI for another configuration, or buy Standard RIs if resale might be needed
Turn on hibernation for an instance that is already runningHibernation is enabled only at launch, with an encrypted root volume big enough for RAMLaunch a new instance (or update the launch template) with hibernation enabled
Rely on Compute Optimizer memory-based rightsizing without the CloudWatch agentEC2 doesn't publish memory by default, so the suggested size may be too smallInstall the CloudWatch agent publishing memory utilization, then wait for at least 30 hours of data
Assume Fargate is the cheapest way to run a service that is busy all dayFargate bills requested vCPU and memory every hour. Steady busy use costs less on committed EC2Fargate for uneven or modest load; EC2 with a Compute Savings Plan for steady high utilization

Compare

Compare
AspectOn-DemandCompute Savings PlansEC2 Instance Savings PlansStandard RIConvertible RISpot Instances
Maximum discountNoneUp to 66%Up to 72%Up to 72%Up to 66%Up to 90%
CommitmentNoneUSD per hour, 1 or 3 yearsUSD per hour, 1 or 3 yearsInstance configuration, 1 or 3 yearsInstance configuration, 1 or 3 yearsNone
FlexibilityAnythingAny family, size, Region, OS, tenancyAny size, OS, tenancy in one family and RegionSize flexible if regional (Linux, default tenancy)Exchange for new attributesAnything, if capacity is available
Covers Fargate and Lambdan/a (list price)YesNoNoNoFargate Spot is separate
Reserves capacityNoNoNoOnly if zonalOnly if zonalNo
Can be interrupted by AWSNoNoNoNoNoYes, with two minutes' notice
Reselln/aNoNoReserved Instance MarketplaceNon/a

For the compute model itself, the cost question is how busy the capacity is:

Compare
ModelYou pay forCheapest whenCost levers
Amazon EC2Instance time, by the second on Linux On-DemandUtilization is steady and highRightsizing, Graviton, Savings Plans, Spot, scheduling
AWS FargateRequested vCPU and memory while each task runsContainers without host management, uneven or modest loadTask size, Fargate Spot, Compute Savings Plans
AWS LambdaRequests plus duration at the configured memorySpiky, event-driven or mostly idle workMemory size (Compute Optimizer), arm64, Compute Savings Plans

Two edge cases solve a location requirement, not a cost one. AWS Outposts runs AWS infrastructure in your own data center for low latency or data residency. AWS Wavelength puts compute at the edge of telecom 5G networks.

Neither is usually the "MOST cost-effective" answer, unless the stem's real constraint is data that can't leave a site. Data transfer charges between AZs and Regions belong to task 4.4. Database commitments belong to task 4.3.

Worked exam scenario

Exam scenario

A media company runs a video transcoding service on Amazon EC2. A fleet of 12 m6i.2xlarge instances is busy around the clock for live channels and must never fall below that size. On-demand jobs from customers add between 0 and 60 more instances during the day; each job writes progress to Amazon S3 and can restart from its last checkpoint. The company plans to move the live-channel fleet to Graviton instances within the next year. Which purchasing strategy meets these requirements MOST cost-effectively?

  1. A.Buy a 3-year EC2 Instance Savings Plan for the m6i family sized to 12 instances. Run the customer jobs on On-Demand Instances.
  2. B.Buy a 1-year Compute Savings Plan sized to 12 instances. Run the restartable jobs on Spot Instances in several instance types.
  3. C.Run all 72 possible instances on Spot Instances in an Auto Scaling group with Capacity Rebalancing turned on.
  4. D.Buy zonal Standard Reserved Instances for 72 m6i.2xlarge instances so capacity is always available.
Show the walkthrough
  1. Underline the requirements. Twelve instances run 24/7 and must never drop. A burst of 0–60 jobs is interruptible and checkpointed. The family will change, and the answer must be MOST cost-effective.
  2. Split the workload. The steady 12 is a commitment candidate. The burst can restart from a checkpoint, which is the definition of a Spot workload.
  3. Pick the commitment. The fleet will change family within a year, so the commitment has to follow it. A Compute Savings Plan applies to any family, so the move to Graviton keeps the discount.
  4. Eliminate A. An EC2 Instance Savings Plan is locked to m6i, so the move to Graviton strands it. On-Demand for restartable jobs also wastes the Spot discount.
  5. Eliminate C. Spot for the live-channel floor breaks "must never fall below". Spot capacity can be reclaimed with two minutes' notice and is never guaranteed.
  6. Eliminate D. Reserving 72 instances pays for up to 60 idle instances whenever demand is low. Standard RIs also can't be exchanged for Graviton types.
  7. Land on B. A flexible commitment covers the floor, and diversified Spot covers the interruptible burst at the deepest discount.

Answer: B

Check your understanding

Question 1: Which TWO kinds of usage can a Compute Savings Plan discount? (Choose TWO.) (Choose TWO.)
Question 2: Which TWO statements about Reserved Instances are true? (Choose TWO.) (Choose TWO.)
Question 3: Finance wants a Savings Plan commitment sized from the account's actual past usage, without a manual analysis. Which AWS feature provides that starting point?
Question 4: A solutions architect turned on Compute Optimizer yesterday. A new EC2 instance launched 10 hours ago still has no recommendation. What is the most likely reason?

Build it

Build an Auto Scaling group with an On-Demand base and Spot above it, and schedule it down for the night. Then watch EC2 refuse to hibernate an instance that wasn't launched for it, in the cost-optimized compute lab.

Key takeaways

  • Rightsize and switch off idle capacity before committing. A commitment sized to waste is billed every hour, and a Savings Plan can be returned only in a short window after purchase.
  • Compute Savings Plans follow you across families, Regions, Fargate and Lambda for up to 66 percent off. EC2 Instance Savings Plans and Standard RIs give up to 72 percent for a fixed family in one Region.
  • Spot (up to 90 percent off, two-minute notice) is for work that can be interrupted. Keep the guaranteed minimum on On-Demand and spread Spot across types and AZs.
  • Savings Plans never reserve capacity. Use On-Demand Capacity Reservations or zonal RIs when capacity must be guaranteed.
  • Lambda wins for spiky or idle-most-of-the-time work, Fargate when you don't want hosts, and committed EC2 for steady high utilization.
  • Rightsize first, then buy for the usage shape: Spot for interruptible work, a Savings Plan or Reserved Instances for the steady baseline, On-Demand for the rest, nothing for idle capacity.

Hands-on lab: Mix On-Demand and Spot, Then Hibernate on Purpose

Sources

Last reviewed