All Products
Search
Document Center

Elastic Compute Service:DescribeSecurityGroups

Last Updated:May 14, 2024

Queries the basic information of security groups.

Operation description

Usage notes

Take note of the following items:

  • The basic information about security groups includes their IDs and descriptions. The response returns security groups in descending order of the IDs of the security groups.
  • We recommend that you use MaxResults and NextToken for a paged query. We recommend that you use MaxResults to specify the maximum number of entries to return for each request. The return value of NextToken is a pagination token, which can be used in the next request to retrieve a new page of results. When you call the DescribeSecurityGroups operation to retrieve a new page of results, set NextToken to the NextToken value that is returned in the previous call and set MaxResults to specify the maximum number of entries to return in this call. If the return value of NextToken is empty, the current page of results is the last page and no more results are to be returned.
  • When you use Alibaba Cloud CLI to call an API operation, you must specify request parameter values of different data types in required formats. For more information, see Parameter format overview.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

There is currently no authorization information disclosed in the API.

Request parameters

ParameterTypeRequiredDescriptionExample
RegionIdstringYes

The region ID. You can call the DescribeRegions operation to query the most recent region list.

cn-hangzhou
SecurityGroupIdsstringNo

The security group IDs. Set this parameter to a JSON array that consists of up to 100 security group IDs. Separate the security group IDs with commas (,).

["sg-bp67acfmxazb4p****", "sg-bp67acfmxazb4p****", "sg-bp67acfmxazb4p****",....]
VpcIdstringNo

The ID of the virtual private cloud (VPC) to which the security group belongs.

vpc-bp67acfmxazb4p****
SecurityGroupTypestringNo

The type of the security group. Valid values:

  • normal: basic security group
  • enterprise: advanced security group
Note If you do not specify this parameter, both basic and advanced security groups are queried.
normal
NextTokenstringNo

The pagination token that is used in the next request to retrieve a new page of results. You do not need to specify this parameter for the first request. You must specify the token that is obtained from the previous query as the value of NextToken.

e71d8a535bd9cc11
MaxResultsintegerNo

The maximum number of entries per page. If you specify this parameter, both MaxResults and NextToken are used for a paged query.

Maximum value: 100.

Default value: 10.

10
NetworkTypestringNo

The network type of the security group. Valid values:

  • vpc
  • classic
vpc
SecurityGroupNamestringNo

The name of the security group.

SGTestName
IsQueryEcsCountbooleanNo

Specifies whether to query the capacity of the security group. If you set this parameter to True, the EcsCount and AvailableInstanceAmount values in the response are valid.

Note This parameter is deprecated.
null
ResourceGroupIdstringNo

The ID of the resource group to which the security group belongs. If this parameter is specified to query resources, up to 1,000 resources that belong to the specified resource group can be displayed in the response. You can call the ListResourceGroups operation to query the most recent resource group list.

Note Resources in the default resource group are displayed in the response regardless of how this parameter is configured.
rg-bp67acfmxazb4p****
Tagobject []No

The tags to add to the security groups.

keystringNo

The tag key of the security group.

Note This parameter will be deprecated in the future. We recommend that you use Tag.N.Key to ensure compatibility.
testkey
KeystringNo

The key of tag N to add to the security group. Valid values of N: 1 to 20.

Up to 1,000 resources that match the tags specified can be returned in the response. To query more than 1,000 resources that have specified tags added, call the ListTagResources operation.

TestKey
ValuestringNo

The value of tag N to add to the security group. Valid values of N: 1 to 20.

TestValue
valuestringNo

The tag value of the security group.

Note This parameter will be deprecated in the future. We recommend that you use Tag.N.Value to ensure compatibility.
testvalue
DryRunbooleanNo

Specifies whether to perform only a dry run, without performing the actual request. Valid values:

  • true: performs only a dry run. The system checks your AccessKey pair, the permissions of the RAM user, and the required parameters. If the request passes the dry run, the DryRunOperation error code is returned. Otherwise, an error message is returned.
  • false: performs a dry run and performs the actual request. If the request passes the dry run, a 2xx HTTP status code is returned and the operation is performed.

Default value: false.

false
SecurityGroupIdstringNo

The security group ID.

sg-bp67acfmxazb4p****
FuzzyQuerybooleanNo
Note This parameter is deprecated.
null
PageNumberintegerNo

The page number.

Pages start from page 1.

Default value: 1.

Note This parameter will be removed in the future. We recommend that you use NextToken and MaxResults for a paged query.
1
PageSizeintegerNo

The number of entries per page.

Valid values: 1 to 50.

Default value: 10.

Note This parameter will be removed in the future. We recommend that you use NextToken and MaxResults for a paged query.
10
ServiceManagedbooleanNo

Specifies whether to query managed security groups. Valid values:

  • true
  • false
false

Response parameters

ParameterTypeDescriptionExample
object
RequestIdstring

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E
RegionIdstring

The region ID of the security group.

cn-hangzhou
NextTokenstring

A pagination token. If the return value of this parameter is empty when MaxResults and NextToken are used for a paged query, no next page exists.

e71d8a535bd9cc11
SecurityGroupsobject []

The information about the security groups.

SecurityGroupIdstring

The ID of the security group.

sg-bp67acfmxazb4p****
SecurityGroupNamestring

The name of the security group.

SGTestName
Descriptionstring

The description of the security group.

TestDescription
SecurityGroupTypestring

The type of the security group. Valid values:

  • normal: basic security group
  • enterprise: advanced security group
normal
VpcIdstring

The ID of the VPC to which the security group belongs.

vpc-bp67acfmxazb4p****
CreationTimestring

The time when the security group was created. The time follows the ISO 8601 standard in the yyyy-MM-ddThh:mmZ format. The time is displayed in UTC.

2021-08-31T03:12:29Z
EcsCountinteger

The number of private IP addresses that are contained in the security group. For more information, see the "Security group capacity" section in Basic security groups and advanced security groups.

If you set IsQueryEcsCount to True, the return value of EcsCount is valid.

Note This parameter is deprecated. The returned quantity is provided only for reference. The actual quantity may differ from the returned quantity.
0
AvailableInstanceAmountinteger

The number of private IP addresses that can be added to the security group. For more information, see the "Security group capacity" section in Basic security groups and advanced security groups.

If you set IsQueryEcsCount to True, the return value of AvailableInstanceAmount is valid.

Note This parameter is deprecated. The returned quantity is provided only for reference. The actual quantity may differ from the returned quantity.
0
ResourceGroupIdstring

The ID of the resource group to which the security group belongs.

rg-bp67acfmxazb4p****
ServiceManagedboolean

Indicates whether the user of the security group is an Alibaba Cloud service or a distributor.

false
ServiceIDlong

The ID of the distributor to which the security group belongs.

12345678910
Tagsobject []

The tags of the security group.

TagValuestring

The value of the tag.

TestValue
TagKeystring

The key of the tag.

TestKey
TotalCountinteger

The total number of security groups returned. If MaxResults and NextToken are specified in the request, the value of this parameter is not returned.

20
PageNumberinteger

The page number.

Note This parameter will be deprecated in the future. We recommend that you use NextToken and MaxResults for a paged query.
1
PageSizeinteger

The number of entries per page.

Note This parameter will be deprecated in the future. We recommend that you use NextToken and MaxResults for a paged query.
10

Examples

Sample success responses

JSONformat

{
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E",
  "RegionId": "cn-hangzhou",
  "NextToken": "e71d8a535bd9cc11",
  "SecurityGroups": {
    "SecurityGroup": [
      {
        "SecurityGroupId": "sg-bp67acfmxazb4p****",
        "SecurityGroupName": "SGTestName",
        "Description": "TestDescription",
        "SecurityGroupType": "normal",
        "VpcId": "vpc-bp67acfmxazb4p****",
        "CreationTime": "2021-08-31T03:12:29Z",
        "EcsCount": 0,
        "AvailableInstanceAmount": 0,
        "ResourceGroupId": "rg-bp67acfmxazb4p****",
        "ServiceManaged": false,
        "ServiceID": 12345678910,
        "Tags": {
          "Tag": [
            {
              "TagValue": "TestValue",
              "TagKey": "TestKey"
            }
          ]
        }
      }
    ]
  },
  "TotalCount": 20,
  "PageNumber": 1,
  "PageSize": 10
}

Error codes

HTTP status codeError codeError messageDescription
400NotSupported.PageNumberAndPageSizeThe parameters PageNumber and PageSize are currently not supported, please use NextToken and MaxResults instead.-
400InValidParameter.NextTokenThe parameter NextToken is invalid.The specified NextToken parameter is invalid.
400MissingParameter.RegionIdThe input parameter RegionId that is mandatory for processing this request is not supplied.The RegionId parameter is required.
400InvalidParameter.SecurityGroupTypeThe specified SecurityGroupType is not valid.The specified SecurityGroupType parameter is invalid.
500InternalErrorThe request processing has failed due to some unknown error.An internal error has occurred. Try again later.

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

Change history

Change timeSummary of changesOperation
2023-11-14The Error code has changed. The request parameters of the API has changedsee changesets
Change itemChange content
Error CodesThe Error code has changed.
    delete Error Codes: 400
    delete Error Codes: 500
Input ParametersThe request parameters of the API has changed.
    Added Input Parameters: ServiceManaged
2023-04-07The Error code has changedsee changesets
Change itemChange content
Error CodesThe Error code has changed.
    Error Codes 400 change
    delete Error Codes: 500
2021-12-05The Error code has changedsee changesets
Change itemChange content
Error CodesThe Error code has changed.
    Error Codes 400 change
    delete Error Codes: 500
2021-10-12The Error code has changedsee changesets
Change itemChange content
Error CodesThe Error code has changed.
    delete Error Codes: 400
    delete Error Codes: 500