User guide
Table Of Contents
- AWS SDK for .NET
- Table of Contents
- AWS SDK for .NET Developer Guide
- Getting Started with the AWS SDK for .NET
- Programming with the AWS SDK for .NET
- AWS SDK for .NET Tutorials and Examples
- Managing ASP.NET Session State with Amazon DynamoDB
- Tutorial: Creating Amazon EC2 Instances with the AWS SDK for .NET
- Tutorial: Grant Access Using an IAM Role and the AWS SDK for .NET
- Tutorial: Amazon EC2 Spot Instances
- Creating and Using an Amazon SQS Queue with the AWS SDK for .NET
- Creating an Amazon Route 53 Hosted Zone and Adding Resource Record Sets
- Additional Resources
- Document History

Spot Instances perform exactly like other Amazon EC2 instances while running, and like other Amazon
EC2 instances, Spot Instances can be terminated when you no longer need them. If you terminate your
instance, you pay for any partial hour used (as you would for On-Demand or Reserved Instances). However,
if your instance is terminated by Amazon EC2 because the Spot Price goes above your bid, you will not
be charged for any partial hour of usage.
This tutorial provides an overview of how to use the .NET programming environment to do the following.
• Submit a Spot Request
• Determine when the Spot Request becomes fulfilled
• Cancel the Spot Request
• Terminate associated instances
Prerequisites
This tutorial assumes that you have signed up for AWS, set up your .NET development environment, and
installed the AWS SDK for .NET. If you use the Microsoft Visual Studio development environment, we
recommend that you also install the AWS Toolkit for Visual Studio. For instructions on setting up your
environment, see Getting Started (p. 3).
Step 1: Setting Up Your Credentials
To begin using this code sample, you need to populate the App.config file with your AWS credentials,
which identify you to Amazon Web Services.You specify your credentials in the files appSettings ele-
ment.The preferred way to handle credentials is to create a profile in the SDK Store, which encrypts your
credentials and stores them separately from any project.You can then specify the profile by name in the
App.config file, and the credentials are automatically incorporated into the application. For more inform-
ation, see Configuring Your AWS SDK for .NET Application (p. 8).
Now that you have configured your settings, you can get started using the code in the example.
Step 2: Setting Up a Security Group
A security group acts as a firewall that controls the traffic allowed in and out of a group of instances. By
default, an instance is started without any security group, which means that all incoming IP traffic, on any
TCP port will be denied. So, before submitting your Spot Request, you will set up a security group that
allows the necessary network traffic. For the purposes of this tutorial, we will create a new security group
called "GettingStarted" that allows connection using the Windows Remote Desktop Protocol (RDP) from
the IP address of the local computer, that is, the computer where you are running the application.
To set up a new security group, you need to include or run the following code sample that sets up the
security group programmatically.You only need to run this code once to create the new security group.
However, the code is designed so that it is safe to run even if the security group already exists. In this
case, the code catches and ignores the "InvalidGroup.Duplicate" exception.
In the code below, we first use AWSClientFactoryClass to create an AmazonEC2 client object. We
then create a CreateSecurityGroupRequest object with the name, "GettingStarted" and a description
for the security group. Finally, we call the ec2.createSecurityGroup API to create the group.
1 AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client();
try
{
Version v2.0.0
52
AWS SDK for .NET Developer Guide
Prerequisites