Skip to Content

Spot Instances

How Spot pricing, requests and interruptions work, how to stop Spot Instances properly, and launching many at once with fleets.

What it is

A Spot Instance runs on EC2 capacity that nobody is using right now, for up to 90% less than On-Demand. The catch: when AWS needs that capacity back for On-Demand customers, it interrupts the instance with a 2-minute warning.

Spot exists because AWS must keep spare capacity for sudden demand. Rather than leave it idle, AWS sells it cheaply to work that can tolerate being stopped.

How Spot pricing works

  • Each instance type in each AZ (a Spot capacity pool) has its own Spot price.
  • AWS sets the Spot price, and it moves slowly, based on long-term supply and demand. The bill uses the current Spot price, never more than the On-Demand price.
  • A maximum price can be set. If the Spot price rises above it, the instance is interrupted. AWS advises not setting one: instances with a maximum price are interrupted more often.
  • The console shows Spot price history for the last three months, per AZ.

The most common reason for interruption isn't price, though. It's AWS needing the capacity back.

Spot requests and interruptions

A Spot request launches a Spot Instance; when interrupted after a 2-minute warning, a persistent request relaunches and a one-time request closes; to stop, cancel the request and then terminate the instances A Spot request launches a Spot Instance; when interrupted after a 2-minute warning, a persistent request relaunches and a one-time request closes; to stop, cancel the request and then terminate the instances

A Spot request's life, and how to end it.
  1. A Spot request is created: how many instances, which type and AZ, and the request type.
    • One-time: once the instance is launched and later ends, the request closes.
    • Persistent: the request stays open. After an interruption, it launches a new instance when capacity is back.
  2. When capacity is available, EC2 launches the Spot Instance, which runs at the Spot price.
  3. When AWS needs the capacity, it sends a 2-minute interruption notice (an EventBridge event and an instance metadata item), then interrupts the instance.
  4. The interruption behaviour chosen in the request decides what happens: terminate (the default), stop, or hibernate. Stop and hibernate need a persistent request.

AWS also sends an earlier signal, the rebalance recommendation, when an instance is at higher risk, so work can move before the 2-minute notice.

Stopping Spot Instances for good

Cancelling a Spot request doesn't terminate its running instances. And terminating instances of a persistent request just makes it launch new ones. So the order matters:

  1. Cancel the Spot request first. Requests that are open, active or disabled can be cancelled.
  2. Then terminate the instances it launched.

Fleets: many Spot Instances at once

A single Spot request asks for one instance type in one pool. If that pool runs out, the request gets nothing. Fleets ask for a target capacity across many pools (instance types × AZs), and can mix Spot and On-Demand.

  • Spot Fleet (in the slides): a set of Spot Instances plus optional On-Demand Instances. It tries to meet the target capacity within the set price limits, choosing from the launch pools defined in it, and stops launching when it reaches the capacity or the maximum cost.
  • EC2 Fleet: the newer API with the same features, used from the CLI.
  • Auto Scaling groups with mixed instance types: what AWS recommends for most fleets, because they add health checks, load balancer integration and scaling. See Auto Scaling groups.

Allocation strategies

How a fleet chooses which pools to launch Spot Instances from:

  • priceCapacityOptimized (recommended): picks the pools with the most spare capacity, then the cheapest of those. Fewest interruptions at a low price. Best for most workloads.
  • capacityOptimized: picks the pools with the most spare capacity. Good when restarting work is expensive.
  • diversified: spreads instances across all pools. Good for availability and long-running work.
  • lowestPrice: uses the cheapest pools. Highest interruption risk; AWS no longer recommends it.

Updated since the slides

AWS now calls Spot Fleet a legacy API with no planned investment. It recommends Auto Scaling groups, or EC2 Fleet when the customer manages the instances directly. The allocation strategies are the same in all three. The lowestPrice strategy is marked not recommended.

Real-world examples

  • A film studio renders frames on 2,000 Spot Instances overnight. If some are interrupted, those frames are re-queued.
  • A data team runs Spark jobs on EMR with Spot task nodes, cutting the cluster bill by 70%.
  • A CI system runs build agents on Spot. An interrupted build just restarts.

Exam tips

  • "Cheapest", "fault-tolerant", "can be interrupted", "flexible start and end time" → Spot.
  • "2-minute warning" → Spot interruption notice; handle it with an EventBridge rule or by checking instance metadata.
  • "Stop Spot Instances and stop new ones launching" → cancel the request, then terminate the instances.
  • "Launch Spot across many instance types and AZs with the fewest interruptions" → a fleet or Auto Scaling group with price-capacity-optimized allocation.
  • "Mix On-Demand for the baseline and Spot for extra capacity" → a fleet or Auto Scaling group with mixed purchase options.

Common traps

  • "Spot for a database or a critical job." No: it can disappear with 2 minutes' notice.
  • "Terminate the instances to end a persistent request." The request just relaunches them; cancel it first.
  • "Bid high to keep your instance." There's no bidding, and setting a maximum price can only increase interruptions.

Hands-on lab: launch and end a Spot Instance

Goal: check Spot prices, launch a Spot Instance from the normal launch wizard, and end it properly.

Costs money

A Spot t3.micro costs well under a cent an hour, plus $0.005 an hour for its public IPv4 address. Finish within the hour and the lab costs a few cents.

Look at the price history

In the EC2 console (us-east-1), open Spot Requests → Pricing history. Choose instance type t3.micro, platform Linux/UNIX, last 3 months. Note the price per AZ compared with the On-Demand line.

Launch a Spot Instance

Choose Launch instances: name saa-spot, tag Project=saa-lab, Amazon Linux 2023, t3.micro, key pair saa-lab-key, security group saa-web-sg (or a new one). Open Advanced details → Purchasing option, tick Spot instances, and keep the default settings (no maximum price, one-time request). Launch.

Find the request

Open Spot Requests. Your request shows fulfilled and the instance ID. In Instances, the instance's Lifecycle column (add it with the gear icon if hidden) says spot.

End it

Terminate the instance. Back in Spot Requests, the one-time request is now closed: there's nothing more to cancel. (With a persistent request, you'd cancel the request first, then terminate.)

Expected result: a working instance at Spot prices, launched exactly like an On-Demand one, and a closed request after you terminate it.

Clean up: make sure Spot Requests shows no open or active requests and the instance is terminated.

AWS documentation

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt