User guide

Table Of Contents
The CreateSecurityGroup method returns a CreateSecurityGroupResponse object.You can get the ID
of the new security group from the response and then use DescribeSecurityGroups with the security
group ID to get the SecurityGroup object for the security group.
if (mySG == null)
{
var newSGRequest = new CreateSecurityGroupRequest()
{
GroupName = secGroupName,
Description = "My sample security group for EC2-VPC",
VpcId = vpcID
};
var csgResponse = ec2Client.CreateSecurityGroup(newSGRequest);
Console.WriteLine();
Console.WriteLine("New security group: " + csgResponse.GroupId);
List<string> Groups = new List<string>() { csgResponse.GroupId };
var newSgRequest = new DescribeSecurityGroupsRequest() { GroupIds = Groups
};
var newSgResponse = ec2Client.DescribeSecurityGroups(newSgRequest);
mySG = newSgResponse.SecurityGroups[0];
}
Adding Rules to Your Security Group
Use the following procedure to add a rule to allow inbound traffic on TCP port 3389 (RDP). This enables
you to connect to a Windows instance. If you're launching a Linux instance, use TCP port 22 (SSH) instead.
Tip
You can get the public IP address of your local computer using a service. For example, we
provide the following service: http://checkip.aws.amazon.com/. To locate another service that
provides your IP address, use the search phrase "what is my IP address". If you are connecting
through an ISP or from behind your firewall without a static IP address, you need to find out the
range of IP addresses used by client computers.
The examples in this section follow from the examples in the previous sections. They assume that mySG
is an existing security group.
To add a rule to a security group
1. Create and initialize an IpPermission object.
string ipRange = "0.0.0.0/0";
List<string> ranges = new List<string>() {ipRange};
var ipPermission = new IpPermission()
{
IpProtocol = "tcp",
FromPort = 3389,
ToPort = 3389,
IpRanges = ranges
};
IpProtocol
The IP protocol.
Version v2.0.0
39
AWS SDK for .NET Developer Guide
Create a Security Group