All Products
Search
Document Center

ENS:CreateSecurityGroup

Last Updated:Dec 04, 2025

Creates a security group.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • For mandatory resource types, indicate with a prefix of * .
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
ens:CreateSecurityGroupcreate
*All Resources
*
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
SecurityGroupNamestringNo

The name of the security group. The name must be 2 to 128 characters in length and can contain letters, digits, colons (:), underscores (_), and hyphens (-). It must start with a letter but cannot start with http:// or https://. It can contain letters, digits, colons (:), underscores (_), and hyphens (-). By default, this parameter is empty.

Dcdn1:2_3-4
DescriptionstringNo

The description. The description must be 2 to 256 characters in length. It must start with a letter but cannot start with http:// or https://.

testDescription
Permissionsarray<object>No

An array of security group rules. You can specify up to 200 IDs of security group rules.

objectNo

The security group rule.

DirectionstringYes

The direction in which the security group rule is applied.

  • egress
  • ingress
ingress
IpProtocolstringYes

The protocol type. Valid values:

  • TCP
  • UDP
  • ICMP
  • ALL: All protocols are supported.
TCP
PortRangestringYes

The range of destination port numbers for the protocols specified in the security group rule. Valid values:

  • If you set IpProtocol to TCP or UDP, the port number range is 1 to 65535. Specify a port range in the format of <Start port number>/<End port number>. Example: 1/200.
  • If you set IpProtocol to ICMP, the port number range is -1/-1.
  • If you set IpProtocol to ALL, the port number range is -1/-1.
80/80
SourcePortRangestringNo

The range of source port numbers for the protocols specified in the security group rule. Valid values:

  • If you set IpProtocol to TCP or UDP, the port number range is 1 to 65535. Specify a port range in the format of <Start port number>/<End port number>. Example: 1/200.
  • If you set IpProtocol to ICMP, the port number range is -1/-1.
  • If you set IpProtocol to ALL, the port number range is -1/-1, which indicates all port numbers.
22/22
PolicystringYes

The action of the security group rule. Valid values:

  • Accept
  • Drop
Accept
DestCidrIpstringNo

The destination IPv4 CIDR block. IPv4 CIDR blocks and IPv4 addresses are supported.

0.0.0.0/0
SourceCidrIpstringNo

The source IPv4 CIDR block. IPv4 CIDR blocks and IPv4 addresses are supported.

0.0.0.0/0
DescriptionstringNo

The description. It must be 2 to 256 characters in length and cannot start with http:// or https://.

testDescription
PriorityintegerYes

The priority of the security group rule. A smaller value specifies a higher priority. Valid values: 1 to 100.

1

Response parameters

ParameterTypeDescriptionExample
object
RequestIdstring

The request ID.

760bad53276431c499e30dc36f6b26be
SecurityGroupIdstring

The ID of the security group.

sg-bp1fg655nh68xyz9i***

Examples

Sample success responses

JSONformat

{
  "RequestId": "760bad53276431c499e30dc36f6b26be",
  "SecurityGroupId": "sg-bp1fg655nh68xyz9i***"
}

Error codes

HTTP status codeError codeError messageDescription
400NoPermissionPermission denied.-
400CallInterfaceCall Interface Happen Error.An error occurred when you call the operation.
400ens.interface.errorFailed to call API.-
400Invalid%sThe specified parameter %s is invalid.-
400Missing%sYou must specify the parameter %s.-
400AuthorizationLimitExceedThe limit of authorization records in the security group reaches.The number of security group rules exceeds the limit.
400SecurityGroupRuleConflict.DuplicatedThe SecurityGroup rule already exists.duplicate security group rules.
400InvalidParameter.PortRangeThe parameter PortRange is not valid.The port range is not configured correctly.
400InvalidParameter.CidrIpThe parameter CidrIp is not valid.The security group rule CIDR block parameter is invalid.
400QuotaExceed.SecurityGroupThe maximum number of security groups is reached.The number of security groups exceeds the quota limit.
400InvalidParameter.%sThe specified field %s invalid. Please check it again.-

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2025-01-02The Error code has changed. The request parameters of the API has changedView Change Details
2023-09-06API Description Update. The Error code has changed. The request parameters of the API has changedView Change Details