User guide
• Set the GroupName property to the security group name of.
• Add the IpPermissionSpecification object from Step 1 to the group's IpPermissions collection.
3. Authorize ingress.
AuthorizeSecurityGroupIngressResponse ingressResponse =
ec2Client.AuthorizeSecurityGroupIngress(ingressRequest);
Pass the request object to Amazon EC2 client's AuthorizeSecurityGroupIngress method, which
returns an AuthorizeSecurityGroupIngressResponse object.
To authorize ingress for additional IP address ranges, ports, or protocols, initialize a new
IpPermissionSpecification instance and add it to the IpPermissions collection before calling
AuthorizeSecurityGroupIngress.
You can also use this procedure to add IP address ranges, ports, and protocols to existing security group.
Each AuthorizeSecurityGroupIngress call adds a rule to the security group up to a maximum of
100 rules. For more information about security groups, see Security Group Concepts.
Important
If you attempt to authorize ingress for an IP address range that has already been authorized,
AuthorizeSecurityGroupIngress throws an exception. The following example shows how
to enumerate a security group's authorized IP address ranges to check for existing ranges, where
secGroup is the group's SecurityGroup object. For a description of how to obtain this object,
see Specify an Amazon EC2 Security Group (p. 44).
foreach (IpPermission ipPerm in secGroup.IpPermissions)
{
foreach (String ipAddress in ipPerm.IpRanges)
{
if (ipAddress == "Address Range")
{
//...
}
}
}
Specify an Amazon EC2 Key Pair
Public Amazon EC2 instances do not have a default password. Instead, you log into the instance by using
a public/private key pair. Amazon EC2 key pairs are distinct from your AWS account's public and private
keys. For more information, see Getting an SSH Key Pair.
Each of your account's Amazon EC2 key pairs is identified by a name. If you want to use an existing key
pair, you can launch your Amazon EC2 instances by using that name, as described later.
Important
Key pair names must be unique. If you attempt to create a key pair with the same name as an
existing key pair, CreateKeyPair returns an exception.You can enumerate your account's
existing key pairs to check for an existing key name as follows:
Version v2.0.0
47
AWS SDK for .NET Developer Guide
Specify an Amazon EC2 Key Pair