AWS Step-by-Step

AWS Spot Instances: Why, When and How To Use Them

Not all workloads are created equal, nor are their price tags. For workloads that are less than mission-critical, organizations can take advantage of steeply discounted AWS Spot Instances. There are a few conditions to keep in mind, however.

I have worked in IT for decades, and over the course of my entire career, there has always been one cardinal, unwritten rule for IT pros: Keep everything running, at all times, no matter what. If you can do that, then you will typically make everyone happy and life will be good.

Of course, anyone who has worked in IT for any length of time knows that this goal isn't always realistic, and that it also ignores one important truth: Although it is possible to make workloads highly available, that availability comes at a cost.

Being that some workloads are inevitably going to be more important than others, the cost of high availability cannot always be justified. It probably does not make sense, for example, to invest as much in protecting a dev/test workload against outages as you might spend to protect your payroll application from downtime.

The vast majority of organizations have some workloads that are mission-critical and other workloads that are not nearly as important. It is possible to reduce the cost of those less-important workloads by taking advantage of Amazon EC2 Spot Instances.

Spot instances are identical to a normal EC2 instance, except for two things. First, spot instances use a different billing model than a regular EC2 instance does. The other difference is that spot instances are subject to interruption. Therefore, you should not use spot instances for running workloads that are mission-critical. Spot instances tend to be useful for dev/test workloads, or perhaps for adding extra computing power to large-scale data analytics projects.

Of course, this raises the question of why spot instances are prone to interruption. In order to answer this question, it is necessary to understand a little bit more about what spot instances are and how the spot instance billing model works.

The key to understanding spot instances is to look at the way that cloud service providers such as Amazon Web Services (AWS) operate. Cloud service providers invest in hardware resources and then release those resources (often on a per-hour basis) to subscribers. One of the problems with this business model, however, is that at any given time, there are likely to be compute resources that are not being utilized. These resources represent hardware capacity that AWS has paid for but are sitting idle, and not making AWS any money at the moment.

Rather than allowing these computing resources to go to waste, AWS offers them at a substantially discounted rate, with the understanding that if someone needs those resources for running a normal EC2 instance, that instance will take priority over spot instances that are using the hardware resources at a discounted rate. In fact, spot instances will be stopped if the resources are needed elsewhere.

Although that describes the basic idea behind spot instances, the spot billing model is just a little bit more complicated than what I just described. In actuality, spot instances do not use flat-rate billing. Instead, AWS calculates a cost for spot instances that is based on supply and demand. As the demand for compute resources increases, spot instance costs also increase. As demand wanes, the cost of a spot resource decreases.

Those who wish to use spot resources simply tell AWS how much they are willing to pay per hour for those resources. Spot instances will continue to run until the cost of the resource meets or exceeds the agreed-upon price. Of course, subscribers are also free to stop or terminate spot instances themselves.

Requesting a spot instance is easy. To do so, open the AWS console and go to the EC2 dashboard. Next, locate the Instances section, and then click on Spot Requests. Now, click the Request Spot Instances button, shown in Figure 1.

[Click on image for larger view.] Figure 1: This is how you request a spot instance.

Upon doing so, you will be taken to the screen shown in Figure 2. As you can see in this figure, AWS gives you the option of placing a one-time spot request, a request for a fleet of spot instances, or a spot block that is valid for a specific length of time. The configuration options vary based on the options that you choose, but you will typically need to specify things such as the number and type of instances, as well as the AMI that you wish to use for the instance.

[Click on image for larger view.] Figure 2: You can request a variety of spot instance types.

As you can see, the configuration process is pretty simple, but there is one last thing that I want to point out. The last option shown in Figure 2 above lets you either set your maximum price (per instance, per hour), but the default behavior is to automatically bid the current spot instance price. The price fluctuates, but will never exceed the normal on-demand rates for EC2 instances.

About the Author

Brien Posey is a 22-time Microsoft MVP with decades of IT experience. As a freelance writer, Posey has written thousands of articles and contributed to several dozen books on a wide variety of IT topics. Prior to going freelance, Posey was a CIO for a national chain of hospitals and health care facilities. He has also served as a network administrator for some of the country's largest insurance companies and for the Department of Defense at Fort Knox. In addition to his continued work in IT, Posey has spent the last several years actively training as a commercial scientist-astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space. You can follow his spaceflight training on his Web site.

Featured

Subscribe on YouTube