User guide

var ec2Client = new AmazonEC2Client(RegionEndpoint.USEast1);
The client object's permissions are determined by the policy that is attached to the profile that you specified
in App.config. To specify the service endpoint, pass the appropriate RegionEndpoint value to the
constructor. For a list of Amazon EC2 service endpoints, see Regions and Endpoints.
Specify an Amazon EC2 Security Group
An Amazon EC2 security group controls which network traffic can flow to and from your Amazon EC2
instances, much like a firewall. For example, you can configure a security group to authorize inbound
traffic from only a specified range of IP addresses, or perhaps only a single address. An AWS account
can have up to 500 security groups, each of which is represented by a user-defined name.
By default, Amazon EC2 associates your instances with a security group that allows no inbound traffic,
which means that you cannot communicate with them.To authorize your Amazon EC2 instances to accept
inbound traffic you must explicitly associate them with a security group that authorizes ingress. For more
information about security groups, go to Security Group Concepts.
If your account already has an appropriately configured security group, you can associate it with your
instances, as follows:
To select an existing security group
1. Create and initialize a DescribeSecurityGroupsRequest object.
var secGroupRequest = new DescribeSecurityGroupsRequest()
{
GroupNames = new List<String> {"GroupName"}
};
The DescribeSecurityGroupsRequest object characterizes the request.This example adds the desired
group to the object's GroupNames property.
2. Pass the request object to the Amazon EC2 client's DescribeSecurityGroups method, which returns
a DescribeSecurityGroupsResponse object.
DescribeSecurityGroupsResponse secGroupResponse =
ec2Client.DescribeSecurityGroups(secGroupRequest);
SecurityGroup secGroup = secGroupResponse.SecurityGroups[0];
The object's SecurityGroups property contains a list of the requested security groups, each of which
is represented by a SecurityGroup object. This example requests a particular group, so the list has
only one member.
Important
If the specified group name does not correspond to one of your account's security groups,
DescribeSecurityGroups throws an exception.
A more robust approach is to enumerate your account's security groups, as follows
Version v2.0.0
44
AWS SDK for .NET Developer Guide
Specify an Amazon EC2 Security Group