I have three exciting news items for Amazon EC2 users:
- You can now use Auto Scaling to place bids on the EC2 Spot Market on your behalf.
- Similarly, you can now place Spot Market bids from within an AWS CloudFormation template.
- We have a new article to show you how to track Spot instance activity with notifications to an Amazon Simple Notification Service (SNS) topic.
Unless you are intimately familiar with the entire AWS product lineup, you may have found the preceding list of items just a bit mysterious. Before I get to the heart of today's announcement, let's review the fundamentals of each product:
You probably know all about Amazon EC2. You can launch servers on an as-needed basis and pay for only the resources that you consume. You can pay the on-demand prices, or you can bid for unused EC2 capacity on the Spot Market, taking advantage of prices that vary in response to changes in supply and demand.
The Simple Notification Service lets you create any number of message topics and to publish messages to the topics.
Together, these features should make it much easier to use Spot Instances, which in turn can help you run EC2 instances more cost-effectively.
With that out of the way, let's dig in!
Spot +Auto Scaling
You can now set up Auto Scaling to make Spot bids on your behalf. As you may know, you must create an Auto Scaling Group and associate a launch configuration with it in order to make use of Auto Scaling. The Auto Scaling group lists the desired Availability Zones, the minimum and maximum size of the group, health checks, and other properties. The launch configuration includes a number of important parameters including the EC2 AMI to launch, the instance type to use, user data to pass to the newly launched instances, and so forth.
You can now include a bid price in your launch configuration if you want to use Spot Instances. Auto Scaling will use that price to continually place bids in an effort to keep the Auto Scaling group at the desired size. You can use this to soak up background capacity at a price point that is economically viable for your application. For example, let's say that you can make good use of up to 10 m1.large instances. You consult the Spot Instance Pricing History in the AWS Management Console, and decide that a bid of $0.12 (twelve cents) per hour will work well for you:
Your Auto Scaling Group would have a minimum and a maximum size of 10, and the launch configuration would set the bid price at $0.12. When sufficient capacity is available at or below or your bid price, your group will expand up to the maximum size, and you'll pay the market price (which could be lower than your bid). The group will contract if there are other demands on the capacity that cause the market price to exceed your bid price. You can alter the bid price at any time by creating a new launch configuration and attaching it to the Auto Scaling Group. Of course, if you want to use On-Demand instances instead, you can simply omit the bid price from your launch configuration.
For even more flexibility, you can use Auto Scaling's scaling policies feature to change the minimum and maximum group sizes at a predetermined future time or dynamically based on your application’s requirements. You could increase your group size at times when your workload is highest or when spot prices are historically low (this is subject to change, of course).
Spot + CloudFormation
You can now create CloudFormation templates that include a bid for Spot capacity as part of an Auto Scaling group (as described above).
The template can describe the construction of an entire application stack. AWS resources in the stack will be created in dependency-based order. The spot bid will be activated after the Auto Scaling group has been created. Here's an example taken directly from a template's definition of an Auto Scaling group:
You can also specify the bid price as a parameter to the template:
In this case, the AWS Management Console will prompt for the price (and the other parameters specified in the template) when you use the template to create a stack
The parameter value can be used directly in the template, or it can be used in other ways. For example, our StarCluster template has been updated to include the spot bid price as a parameter and to pass it in to the starcluster command:
In addition to the Starcluster template that I mentioned above, we are also releasing two other templates today:
- The Bees With Machine Guns template gives you the power to create a swarm of bees (EC2 micro instances) to load test your web site.
- The Asynchronous Processing template adjusts the number of workers (EC2 instances) that are pulling data from an SQS queue, increasing the number of workers when the queue depth rises above a certain level and reducing it when the number of empty polls on the queue starts to grow. Even though it is of modest size, this template illustrates a number of clever techniques. It installs some packages, configures a crontab entry, loads some Perl code, and uses CloudWatch alarms for scaling.
My advice? Spend some time digging in to these templates to get a better understanding of how you can use the very potent combination of Spot Instances, Auto Scaling groups, and CloudFormation to design complex, parameterized application stacks that can be instantiated transactionally (all or nothing) with just a few clicks. Print them out, draw some diagrams, and gain a better appreciation for how they work -- I guarantee you that it will be time well spent, and that you will walk away with some really good ideas!
Notifications Application / Tutorial
We've written a new article to show you how to track Spot instance activity programmatically. Along with this article, we're distributing a sample application in source code form. As described in the article, the application uses the EC2 APIs to track three types of items, all within a designated region:
- The list of EC2 instances currently running in your account (Spot and On-Demand).
- Your current Spot Instance requests.
- Current prices for Spot Instances.
When the application detects a change in any of the items that it monitors, it uses the Simple Notification Service to send a notification. You can use this notification-based model to decouple your application's bid generation mechanism from the actual processing logic, and you can also do a better job of dealing with processing interruptions if you are outbid and some of your Spot Instances are terminated.
The notification is sent as a simple XML document; here's a sample:
The application was written in Java using the AWS SDK for Java. Because the applications stores all of its configuration information and persistent data in Amazon SimpleDB, you can make configuration changes (e.g. updating notification thresholds) by storing new values in the appropriate items in the application's SimpleDB domain.
I interviewed Dave Ward of the EC2 Spot Instance team for The AWS Report. Here's what Dave had to say:
One small correction -- It turns out that the Chocolate + Peanut Butter analogy that I used is out of date. All of the cool kids on the EC2 team now use term Crazy Delicious to refer to the unholy combination of Mr. Pibb and Red Vines.
Talk to Us
We would love to see what kinds of CloudFormation templates you come up with for use with Spot Instances. Please feel free to post them in the CloudFormation forum or leave a note on this post. Also, if you have thoughts on the features you want next on Spot please let us know at email@example.com or via a note below.