Amazon AWS SDK Guide de l'utilisateur Page 75 : Creating a Security Group

/ 155
Table des matières
To create a security group for EC2-Classic
Create and initialize a
CreateSecurityGroupRequest
object. Assign a name and description to the
GroupName
and
Description
properties, respectively.
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-Classic"
};
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];
}
To create a security group for EC2-VPC
Create and initialize a
CreateSecurityGroupRequest
object. Assign values to the
GroupName
,
Description
,
and
VpcId
properties.
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];
}
Version v2.0.0
71
AWS SDK for .NET Developer Guide
Tutorial: Creating Amazon EC2 Instances

Fichier PDF · ·

Imprimer

Imprimer le document

Partage

Questions sur Amazon AWS SDK

Pas encore de questions sur ce manuel. Posez la première.

Poser une question

Nous répondons à partir du manuel et indiquons la page. La question est publiée sur le site après vérification.

Toutes les questions et réponses ›

Produits connexes et manuels pour Logiciel Amazon AWS SDK