User guide

The sample code in this tutorial is written in C#, but you can use the AWS SDK for .NET with any compatible
language.The AWS SDK for .NET installs a set of C# project templates, so the simplest way to start this
project is to open Visual Studio, select New Project from the File menu, and then select AWS Empty
Project.
Prerequisites
Before you begin, be sure that you have created an AWS account and that you have set up your AWS
credentials. For more information, see Getting Started (p. 3).
Tasks
The following tasks demonstrate how to manage EC2 instances using the AWS SDK for .NET.
Create an Amazon EC2 Client (p. 69)
Create a Security Group (p. 69)
Create a Key Pair (p. 73)
Launch an EC2 Instance (p. 74)
Terminate an EC2 Instance (p. 79)
Create an Amazon EC2 Client Using the SDK for .NET
Create an Amazon EC2 client to manage your EC2 resources, such as instances and security groups.
This client is represented by an AmazonEC2Client object, which you can create as follows:
var ec2Client = new AmazonEC2Client();
The permissions for the client object are determined by the policy that is attached to the profile that you
specified in the App.config file. By default, we use the region specified in App.config.To use a
different region, pass the appropriate RegionEndpoint value to the constructor. For more information, see
Regions and Endpoints in the AWS General Reference.
Create a Security Group Using the SDK for .NET
Create a security group, which acts as a virtual firewall that controls the network traffic for one or more
EC2 instances. By default, Amazon EC2 associates your instances with a security group that allows no
inbound traffic.You can create a security group that allows your EC2 instances to accept certain traffic.
For example, if you need to connect to an EC2 Windows instance, you must configure the security group
to allow RDP traffic.You can create a security group using the Amazon EC2 console or the SDK for .NET.
You create a security group for use in either EC2-Classic or EC2-VPC. For more information about
EC2-Classic and EC2-VPC, see Supported Platforms in the Amazon EC2 User Guide for Microsoft
Windows Instances.
Alternatively, you can create a security group using the Amazon EC2 console. For more information, see
Amazon EC2 Security Groups in the Amazon EC2 User Guide for Microsoft Windows Instances.
Contents
Enumerating Your Security Groups (p. 70)
Creating a Security Group (p. 70)
Adding Rules to Your Security Group (p. 72)
Version v2.0.0
69
AWS SDK for .NET Developer Guide
Tutorial: Creating Amazon EC2 Instances