User guide
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
element. 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
information, see Configuring Your AWS SDK for .NET Application (p. 8).
The following appSettings example specifies a profile named development.
<appSettings>
<add key="ClientSettingsProvider.ServiceUri" value="" />
<add key="AWSProfileName" value="development"/>
</appSettings>
To learn more about setting up security credentials, see the Amazon Elastic Compute Cloud User Guide.
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
{
5 CreateSecurityGroupRequest securityGroupRequest = new CreateSecurity
GroupRequest();
securityGroupRequest.GroupName = "GettingStartedGroup";
securityGroupRequest.GroupDescription = "Getting Started Security Group";
ec2.CreateSecurityGroup(securityGroupRequest);
Version v2.0.0
53
AWS SDK for .NET Developer Guide
Prerequisites