Optimize Your Compute with AWS Spot Instances

Do you want to pay less for your compute capacity? Keep reading to learn how AWS Spot Instances can help reduce your costs.

What are Spot Instances?

Spot Instances are unused EC2 instances that AWS has available in excess. Using spot instances can save you up to 90% off the On-Demand pricing for any available instance type. However, AWS is allowed to interrupt spot instances and reclaim them for any necessary On-Demand compute capacity needed. AWS does offer ways to mitigate these interruptions, or at the very least, they will provide a 2 minute warning before the instance is stopped.

On-Demand vs Reserved vs Spot Instances

AWS allows users to create EC2 instances with many allocation types. On-Demand instances allow the user to pay for compute capacity as it is needed. These types of instances are best used for workloads with many spikes in capacity needs, or for initially figuring out what how much capacity an application may require.

Reserved instances are allocated for 1-3 years at a time, thus they require a commitment. However, with the long-term commitment, there are some discounts available from the On-Demand pricing. Reserved instances would be the best choice if the application has steady usage patterns.

Spot instances, as mentioned previously, can be interrupted by AWS. Additionally, the pricing for each instance type can change overtime. Albeit, the change is gradual, and correlates with long-term supply and demand requirements.

Use Cases

Spot Instances are the best to use on workloads that are fault-tolerant, flexible, stateless, and loosely-coupled. Some examples of these include: Big Data, Containerized Workloads, Image/Video Rendering, Web Applications and Services and Batch Processing.

How TLG Aerospace is Utilizing Spot Instances for Their Business

Credit: AWS Online Tech Talks

Read about TLG Aerospace’s Case Study for more information.

How do Spot Instances work?

Spot instances draw from spare compute capacity within instance pools. Each instance type will have its own pool of instances in an availability zone within their chosen region. Each instance pool is priced slightly differently in each availability zone based on supply and demand requirements. While the instance is running, the account holder is charged the same rate as all others using the compute capacity in that instance pool.

How Do Spot Instances Work? Credit: Amazon EC2 Spot Instances – Getting Started

While running, instances can be automatically stopped by AWS, often referred to as an interruption. When AWS interrupts Spot instances, the default behavior is to terminate an instance. However, a somewhat unique feature of certain types of Spot instances is instance hibernation. Instance hibernation will pause the instance and RAM data is persisted, allowing the instance’s operations to resume exactly where they left off. No additional charges for usage are incurred while the instance is in hibernation. The biggest downside of hibernation? AWS controls when the instance can resume, not the user.

Best Practices

Spot Instances have a few best practices to optimize their usage.

Spot Rules – remembering a couple key aspects about AWS Spot Instances can help save costs.

  1. AWS will reclaim the compute capacity of an instance if it is needed elsewhere. However, the user is provided with a 2 minute warning when this occurs.
  2. Each instance pool will be priced differently for each instance type in each availability zone. Remember, these costs will slowly change over time.

Instance Flexibility – Check what types of instances can handle your workload. Requesting multiple types of instances within one Spot request can lead to higher availability. By having a set maximum price, and being flexible with a variety of instance types, the user could pay a lower price, but have a higher compute capacity allocated to them.

Availability Zone Flexibility – Within one geographical region, there are at least 2 availability zones. Allowing availability zone flexibility can double, triple, or perhaps even quadruple the number of instance pools available to draw from. Allowing availability zone flexibility can decrease the likelihood of an instance interruption.

AWS also offers some transparency with their spot instance pricing. The Spot Instance Advisor provides a table similar to the above one with real-time cost estimates. The spot instance advisor allows users to set minimum vCPUs and GB of RAM required for their spot instances, then look to see the savings and chance that an interruption will occur in that region.

How To Launch an EC2 Spot Request

It is easy to set up an EC2 Spot Request for a workload.

Starting at the AWS Console use the top toolbar to search for the EC2 Management console.

Once at the EC2 Management Console, navigate to the left sidebar and under Instances select Spot Requests.

Once on the Spot Requests page, select Request Spot Instance. This will direct you to a Spot Instance Request launcher.

Under Launch Parameters select manually configure launch parameters. Then select the AMI for the workload. If there is an existing AMI set up for the workload select that AMI. Otherwise, Amazon has many pre-configured AMI available. Next, select a key pair to use for the spot instances. If there is already a key pair available, choose the corresponding name. Otherwise, create a new key pair.

Under Additional Launch Parameters, we can optionally select a security group to assign to the instance. AWS will use a default security group if none are specified.

Under Target Capacity select the number of instances required for the workload. Normally, it is best to use the default On-Demand pricing as the maximum allowed.

Note: Setting a higher maximum price does not lend to fewer interruptions, so unless there is a specific budget that is allowed and is less than the default pricing, do not set a maximum price.

Under Network keep all defaults. As stated previously, having no availability zone preferences reduces the chance of interruptions.

Under Instance Type Requirements, select manually select instance types > Add Instance Types. Then select the minimum instance type that is required for the workload.

As noted in Best Practices, it is wise to select multiple instance types that are suitable for the workloads capacity requirements. AWS kindly provides an indicator of how strong your spot request is. Only selecting 1 instance type will often be a weak spot request, and lead to more interruptions or even no availability.

Under Allocation Strategy, it is often best to stick with the recommended default, capacity optimized. Capacity optimized will help lower the chances of interruptions.

Finally, once the configurations have been set select the Launch button at the bottom of the screen.

After Launching your Spot Instance request, the user will be re-directed to the Spot Instance Management Console. There you will find a new Request ID. Select the Request ID and a summary page will show up below the request.

Toggle the Instances tab in the summary to find the instances you requested. Selecting the ID of one will bring you to the Instances EC2 Management Console. From there you can monitor the instance and find the information required to access the instance should it be required.

Sources:

Amazon EC2 Spot Instances – Getting Started. Amazon. Retrieved October 3, 2022, from https://aws.amazon.com/ec2/spot/getting-started/ 

Amazon EC2 FAQ. Amazon. Retrieved October 3, 2022, from https://aws.amazon.com/ec2/faqs/#Spot_instances