Open In App

Amazon Web Services – Spot Rules in EC2 Spot Instances

Last Updated : 08 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we are going to walk through a few simple rules to follow when launching Amazon EC2 spot instances. Spot instances enable you to optimize costs on an AWS cloud and scale the throughput of your application up to 10 times for the same budget.

To help users manage their Spot Instances, AWS provides Spot Rules. These are settings that allow users to define when their Spot Instances should start, stop, or terminate based on certain conditions

  1. Interruption Behavior: This rule defines the action to take when the Spot Instance is interrupted by AWS due to spot market fluctuations or other reasons. Users can choose to either stop, terminate, or hibernate the instance.
  2. Start Time: Users can specify the earliest time the Spot Instance should start. This allows users to launch instances during off-peak hours when Spot prices are lower.
  3. End Time: Users can specify the latest time the Spot Instance should run. This can help users avoid incurring unexpected charges if the Spot price spikes above their budget.
  4. Instance Types: Users can specify the type of instances they want to launch. This can help users optimize their workloads for specific use cases.
  5. Maximum Price: Users can specify the maximum price they are willing to pay for the Spot Instance. If the Spot price exceeds this value, the instance will be terminated.

In this article, we will discuss two simple rules to follow when thinking about launching spot instances:

Rule 1: 

Spot pools have separate prices and change less frequently. Each instance type, size, and availability zone in every region is a separate spot pool. 

For example, take a look at the below image where c3.2xlarge in us-east-1c has a separate price and for c4.8xlarge in us-east-1d has a separate price for c3.2xlarge  is $10.9 right now. But it could be $0.9 tomorrow and it adjusts based on long-term supply and demand.

c3.2xlarge on US east 1c

c4.8xlarge on US east 1d

Rule 2:

Amazon EC2 will give you a two-minute warning when AWS needs the capacity back. 

You can request spot capacity similar to on-demand and always pay the current spot price. When AWS needs the capacity back, you will get a two-minute warning. AWS sends you the notification about the spot instant status. There are two reasons your spot instance could be marked for termination:

  1. The current spot price has risen above your maximum willingness to pay.
  2. The capacity is no longer available to serve your instance.

The bit status of your spot instance request is set to marked for termination and spot termination time metadata is set to a time precisely two minutes in the future.

Example 1: Response you will get when you call describe-spot-instance-requests API for the instance that got marked for termination.

"Status": {
            "Update Time" : "2022-03-02T18:16:21.000z",
            "Code" : "marked-for-termination",
            "Message" : "The Spot Instance is marked for termination",
        },

Example 2: Response you will get when you call describe-spot-instance-requests API for the instance that got terminated.

"Status": {
            "Update Time" : "2022-03-02T18:16:21.000z",
            "Code" : "instance-terminated-capacity-oversubscribed",
            "Message" : "Your Spot Instance was terminated as there
                            is no more unused capacity available
                            in this pool.",
        },

AWS EC2 Spot Instances Termination:

When using Amazon EC2 Spot Instances, it is important to be aware that AWS may need the capacity back and will give a two-minute warning before terminating the spot instance. There are two reasons your spot instance may be marked for termination:

  1. The current spot price has risen above your maximum willingness to pay.
  2. The capacity is no longer available to serve your instance.

When AWS needs the capacity back, the status of your spot instance request will be set to “marked for termination” and the spot termination time metadata will be set to a time exactly two minutes in the future. If the instance is actually terminated, the status will be updated to “instance-terminated” with a specific message indicating the reason for the termination.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads