> For the complete documentation index, see [llms.txt](https://karansingh.gitbook.io/aws-saa-c02/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://karansingh.gitbook.io/aws-saa-c02/ec2/spot-instances.md).

# Spot Instances

* Take advantage of **unused EC2 capacity in AWS**.<br>
* They can have up to a **90% discount compared to On-Demand** prices.

## Concepts

* **Spot Instance pool:**
  * A **set of unused EC2 instances with the same properties**, such as the same instance type, operating system, Availability Zone, and network platform.<br>
* **Spot price:**
  * The **current price of a Spot Instance per hour**.<br>
* **Spot Instance request:**
  * A **request for a Spot Instance**.<br>
  * The request **provides the maximum price per hour that you are willing to pay** for a Spot Instance.<br>
  * They can either be **one-time or persistent (persistent means the request would keep replacing instances if it does not meet your specified target)**.<br>
  * **Cancelling a spot request won't terminate instances**.
    * To cancel a persistent request, first you would have to cancel the request, then terminate the instances.<br>
* Spot Instance interruption:
  * EC2 terminates/stops your Spot Instance when the Spot price exceeds the maximum price for your request or capacity is no longer available.<br>
  * EC2 provides a Spot Instance interruption notice, which gives the instance a two-minute warning before it is interrupted.

## Spot Fleets

* A **collection, or fleet, of Spot Instances, and optionally On-Demand Instances**.

* The Spot Fleet attempts to launch the number of Spot Instances and On-Demand Instances to **meet the target capacity that you specified in the Spot Fleet request**.<br>

* Spot Instance pool:
  * A set of unused EC2 instances with the same properties, such as the same instance type, operating system, Availability Zone, and network platform.<br>

* Strategies:
  * `lowestPrice`
    * The **Spot Instances come from the pool with the lowest price**.
    * This is the **default strategy**.
    * For **cost optimization**.<br>
  * `diversified`
    * The **Spot Instances are distributed across all pools**.
    * For **highly available and long workloads**.<br>
  * `capacityOptimized`
    * The **Spot Instances come from the pool with optimal capacity** for the number of instances that are launching.
    * For **best performance**.

## Spot Blocks

* These are **spot Instances with a defined duration**.<br>
* They are designed not to be interrupted and will run continuously for the duration you select.
  * Makes them ideal for jobs that take a finite time to complete, such as batch processing, encoding and rendering, modelling and analysis, and continuous integration.
