User guide

computer. If your connection to the Internet is mediated by a firewall or some other type of proxy, you will
need to determine the external IP address that the proxy uses. One technique is to query a search engine
such as Google or Bing with the string: "what is my IP address".
1
// TODO - Change the code below to use your external IP address.
String ipSource = "XXX.XXX.XXX.XX/32";
5 List<String> ipRanges = new List<String>();
ipRanges.Add(ipSource);
List<IpPermissionSpecification> ipPermissions = new List<IpPermissionSpe
cification>();
IpPermissionSpecification ipPermission = new IpPermissionSpecification();
10 ipPermission.IpProtocol = "tcp";
ipPermission.FromPort = 3389;
ipPermission.ToPort = 3389;
ipPermission.IpRanges = ipRanges;
ipPermissions.Add(ipPermission);
The final step is to call ec2.authorizeSecurityGroupIngress with the name of our security group
and the ipPermission object.
1 try {
// Authorize the ports to be used.
AuthorizeSecurityGroupIngressRequest ingressRequest = new AuthorizeSe
curityGroupIngressRequest();
ingressRequest.IpPermissions = ipPermissions;
5 ingressRequest.GroupName = "GettingStartedGroup";
ec2.AuthorizeSecurityGroupIngress(ingressRequest);
} catch (AmazonEC2Exception ae) {
if (String.Equals(ae.ErrorCode, "InvalidPermission.Duplicate", String
Comparison.InvariantCulture))
{
10 Console.WriteLine(ae.Message);
}
else
{
throw;
15 }
}
You can also create the security group using the AWS Toolkit for Visual Studio. Go to the toolkit
documentation for more information.
Step 3: Submitting Your Spot Request
To submit a Spot Request, you first need to determine the instance type, the Amazon Machine Image
(AMI), and the maximum bid price you want to use.You must also include the security group we configured
previously, so that you can log into the instance if you want to.
There are several instance types to choose from; go to Amazon EC2 Instance Types for a complete list.
For this tutorial, we will use t1.micro.You'll also want to get the ID of a current Windows AMI. For more
information, see Finding an AMI in the Amazon EC2 User Guide for Microsoft Windows Instances.
There are many ways to approach bidding for Spot instances. To get a broad overview of the various
approaches, you should view the Bidding for Spot Instances video. However, to get started, we'll describe
Version v2.0.0
82
AWS SDK for .NET Developer Guide
Tutorial: Amazon EC2 Spot Instances