User guide

three common strategies: bid to ensure cost is less than on-demand pricing; bid based on the value of
the resulting computation; bid so as to acquire computing capacity as quickly as possible.
Reduce Cost Below On-Demand You have a batch processing job that will take a number of hours
or days to run. However, you are flexible with respect to when it starts and when it completes.You
want to see if you can complete it for less cost than with On-Demand Instances.You examine the Spot
Price history for instance types using either the AWS Management Console or the Amazon EC2 API.
For more information, go to Viewing Spot Price History. After you've analyzed the price history for your
desired instance type in a given Availability Zone, you have two alternative approaches for your bid:
You could bid at the upper end of the range of Spot Prices (which are still below the On-Demand
price), anticipating that your one-time Spot Rrequest would most likely be fulfilled and run for enough
consecutive compute time to complete the job.
Or, you could bid at the lower end of the price range, and plan to combine many instances launched
over time through a persistent request. The instances would run long enough, in aggregate, to
complete the job at an even lower total cost. (We will explain how to automate this task later in this
tutorial.)
Pay No More than the Value of the Result You have a data processing job to run.You understand
the value of the job's results well enough to know how much they are worth in terms of computing costs.
After you've analyzed the Spot Price history for your instance type, you choose a bid price at which the
cost of the computing time is no more than the value of the job's results.You create a persistent bid
and allow it to run intermittently as the Spot Price fluctuates at or below your bid.
Acquire Computing Capacity Quickly You have an unanticipated, short-term need for additional
capacity that is not available through On-Demand Instances. After you've analyzed the Spot Price
history for your instance type, you bid above the highest historical price to provide a high likelihood that
your request will be fulfilled quickly and continue computing until it completes.
After you choose your bid price, you are ready to request a Spot Instance. For the purposes of this tutorial,
we will set our bid price equal to the On-Demand price ($0.03) to maximize the chances that the bid will
be fulfilled.You can determine the types of available instances and the On-Demand prices for instances
by going to Amazon EC2 Pricing page.
To request a Spot Instance, you simply need to build your request with the parameters we have specified
so far. We start by creating a RequestSpotInstanceRequest object.The request object requires the
number of instances you want to start (2) and the bid price ($0.03). Additionally, you need to set the
LaunchSpecification for the request, which includes the instance type, AMI ID, and security group
you want to use. Once the request is populated, you call the requestSpotInstances method on the
AmazonEC2Client object. An example of how to request a Spot Instance is shown below.
1 RequestSpotInstancesRequest requestRequest = new RequestSpotInstances
Request();
requestRequest.SpotPrice = "0.03";
requestRequest.InstanceCount = 2;
5
LaunchSpecification launchSpecification = new LaunchSpecification();
launchSpecification.ImageId = "ami-fbf93092"; // latest Windows AMI as
of this writing
launchSpecification.InstanceType = "t1.micro";
10 launchSpecification.SecurityGroup.Add("GettingStartedGroup");
requestRequest.LaunchSpecification = launchSpecification;
RequestSpotInstancesResponse requestResult = ec2.RequestSpotInstances(re
questRequest);
Version v2.0.0
83
AWS SDK for .NET Developer Guide
Tutorial: Amazon EC2 Spot Instances