Spot Instances

Show slides

c03 ec2 purchasingoptions spotinstances


c03 ec2 purchasingoptions spotinstances request


c03 ec2 purchasingoptions spotinstances termination


Concepts

  • Spot capacity pool – A set of unused EC2 instances with the same instance type (for example, m5.large) and Availability Zone.

  • Spot price – The current price of a Spot Instance per hour.

  • Spot Instance request – Requests a Spot Instance. When capacity is available, Amazon EC2 fulfills your request. A Spot Instance request is either one-time or persistent. Amazon EC2 automatically resubmits a persistent Spot Instance request after the Spot Instance associated with the request is interrupted.

  • EC2 instance rebalance recommendation – Amazon EC2 emits an instance rebalance recommendation signal to notify you that a Spot Instance is at an elevated risk of interruption. This signal provides an opportunity to proactively rebalance your workloads across existing or new Spot Instances without having to wait for the two-minute Spot Instance interruption notice.

  • Spot Instance interruption – Amazon EC2 terminates, stops, or hibernates your Spot Instance when Amazon EC2 needs the capacity back. Amazon EC2 provides a Spot Instance interruption notice, which gives the instance a two-minute warning before it is interrupted.

With spot instances AWS sets a price for unused capacity (Spot price) depending on AZ, machine type and overall available capacity. You define a Max price you’re willing to pay (must be higher than Spot price) for instances, and as long as your price is greater than or equal to the Spot price you keep paying the spot price. If the Spot price raises above your thereshold your instances are terminated (or whatever options you set in the request; One-time requests only allow for termination).

Request types

  • A one-time Spot Instance request remains active until Amazon EC2 launches the Spot Instance, the request expires, or you cancel the request. If capacity is not available, your Spot Instance is terminated and the Spot Instance request is closed.

  • A persistent Spot Instance request remains active until it expires or you cancel it, even if the request is fulfilled. If capacity is not available, your Spot Instance is interrupted. After your instance is interrupted, when capacity becomes available again, the Spot Instance is started if stopped or resumed if hibernated. You can stop a Spot Instance and start it again if capacity is available. If the Spot Instance is terminated (irrespective of whether the Spot Instance is in a stopped or running state), the Spot Instance request is opened again and Amazon EC2 launches a new Spot Instance.

Best practices

  • Prepare individual instances for interruptions

  • Be flexible about instance types and Availability Zones

  • Use EC2 Auto Scaling groups or EC2 Fleet to manage your aggregate capacity

  • Use the price and capacity optimized allocation strategy: because this strategy automatically provisions instances from the most-available Spot capacity pools that also have the lowest possible price. You can also take advantage of the price-capacity-optimized allocation strategy in EC2 Fleet

  • Use proactive capacity rebalancing

  • Monitor rebalance recommendation signals: The rebalance recommendation signal is made available as an event that is sent to Amazon EventBridge (formerly known as Amazon CloudWatch Events) and as instance metadata on the Spot Instance

Use cases

  • Batch jobs

  • Data analysis

  • Image processing

  • Any distributed workloads

  • Workloads with a flexible start and end time