AWS SDK Version 4 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Container for the parameters to the CreateSecurityGroup operation. Creates a security group.

A security group acts as a virtual firewall for your instance to control inbound and outbound traffic. For more information, see Amazon EC2 security groups in the Amazon EC2 User Guide and Security groups for your VPC in the Amazon VPC User Guide.

When you create a security group, you specify a friendly name of your choice. You can't have two security groups for the same VPC with the same name.

You have a default security group for use in your VPC. If you don't specify a security group when you launch an instance, the instance is launched into the appropriate default security group. A default security group includes a default rule that grants instances unrestricted network access to each other.

You can add or remove rules from your security groups using AuthorizeSecurityGroupIngress, AuthorizeSecurityGroupEgress, RevokeSecurityGroupIngress, and RevokeSecurityGroupEgress.

For more information about VPC security group limits, see Amazon VPC Limits.

Inheritance Hierarchy

System.Object
  Amazon.Runtime.AmazonWebServiceRequest
    Amazon.EC2.AmazonEC2Request
      Amazon.EC2.Model.CreateSecurityGroupRequest

Namespace: Amazon.EC2.Model
Assembly: AWSSDK.EC2.dll
Version: 3.x.y.z

Syntax

C#
public class CreateSecurityGroupRequest : AmazonEC2Request
         IAmazonWebServiceRequest

The CreateSecurityGroupRequest type exposes the following members

Constructors

NameDescription
Public Method CreateSecurityGroupRequest()

Empty constructor used to set properties independently even when a simple constructor is available

Public Method CreateSecurityGroupRequest(string, string)

Instantiates CreateSecurityGroupRequest with the parameterized properties

Properties

NameTypeDescription
Public Property Description System.String

Gets and sets the property Description.

A description for the security group.

Constraints: Up to 255 characters in length

Valid characters: a-z, A-Z, 0-9, spaces, and ._-:/()#,@[]+=&;{}!$*

Public Property DryRun System.Nullable<System.Boolean>

Gets and sets the property DryRun.

Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Public Property GroupName System.String

Gets and sets the property GroupName.

The name of the security group. Names are case-insensitive and must be unique within the VPC.

Constraints: Up to 255 characters in length. Can't start with sg-.

Valid characters: a-z, A-Z, 0-9, spaces, and ._-:/()#,@[]+=&;{}!$*

Public Property TagSpecifications System.Collections.Generic.List<Amazon.EC2.Model.TagSpecification>

Gets and sets the property TagSpecifications.

The tags to assign to the security group.

Starting with version 4 of the SDK this property will default to null. If no data for this property is returned from the service the property will also be null. This was changed to improve performance and allow the SDK and caller to distinguish between a property not set or a property being empty to clear out a value. To retain the previous SDK behavior set the AWSConfigs.InitializeCollections static property to true.

Public Property VpcId System.String

Gets and sets the property VpcId.

The ID of the VPC. Required for a nondefault VPC.

Examples

This example creates a security group for the specified VPC.

To create a security group for a VPC


var client = new AmazonEC2Client();
var response = client.CreateSecurityGroup(new CreateSecurityGroupRequest 
{
    Description = "My security group",
    GroupName = "my-security-group",
    VpcId = "vpc-1a2b3c4d"
});

string groupId = response.GroupId;

            

Version Information

.NET:
Supported in: 8.0 and newer, Core 3.1

.NET Standard:
Supported in: 2.0

.NET Framework:
Supported in: 4.7.2 and newer