Queries the basic information of security groups.

Description

Before you call this operation, take note of the following items:

  • The basic information of security groups includes their IDs and descriptions. The response returns security groups ordered in descending order based on their IDs.
  • We recommend that you use the NextToken and MaxResults parameters for a pagination query. We recommend that you set MaxResults to specify the maximum number of entries to return in each request. The returned value of NextToken is a pagination token, which can be used in the next request to retrieve a new page of results. When you perform the next request, set NextToken to the NextToken value 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. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes DescribeSecurityGroups

The operation that you want to perform. Set the value to DescribeSecurityGroups.

RegionId String Yes cn-hangzhou

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

VpcId String No vpc-bp67acfmxazb4p****

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

PageNumber Integer No 1

The number of the page to return.

Pages start from page 1.

Default value: 1.

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

The number of entries to return on each page.

Maximum value: 50.

Default value: 10.

Note This parameter will be deprecated in the future. We recommend that you use the NextToken and MaxResults parameters for a paged query.
SecurityGroupIds String No ["sg-bp67acfmxazb4p****", "sg-bp67acfmxazb4p****", "sg-bp67acfmxazb4p****",....]

The IDs of security groups. The value is a JSON array that consists of up to 100 security group IDs. Separate the security group IDs with commas (,).

ResourceGroupId String No rg-bp67acfmxazb4p****

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 list of resource groups.

Note Resources in the default resource group are displayed in the response regardless of how this parameter is set.
NetworkType String No vpc

The network type of the security group. Valid values:

  • vpc
  • classic
SecurityGroupId String No sg-bp67acfmxazb4p****

The ID of the security group.

SecurityGroupName String No SGTestName

The name of the security group.

IsQueryEcsCount Boolean No null
Note This parameter is deprecated.
FuzzyQuery Boolean No null
Note This parameter is deprecated.
SecurityGroupType String No normal

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.
DryRun Boolean No false

Specifies whether to perform a dry run. Valid values:

  • true: performs a dry run. The systems checks whether your AccessKey pair is valid, whether RAM users are granted permissions, and whether the required parameters are specified. If the request fails the dry run, an error message is returned. If the request passes the dry run, the DryRunOperation error code is returned.
  • false: performs a dry run and sends the request. If the request passes the dry run, a 2xx HTTP status code is returned and the operation is performed.

Default value: false.

Tag.N.key String No testkey

The key of tag N of the security group.

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

The tag key of 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. If the total number of resources that match the tags exceed 1,000, we recommend that you call the ListTagResources operation.

Tag.N.Value String No TestValue

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

Tag.N.value String No testvalue

The tag value of the security group.

Note This parameter will be deprecated in the future. We recommend that you use the Tag.N.Value parameter to ensure future compatibility.
NextToken String No e71d8a535bd9cc11

The query token. Set the value to the NextToken value returned in the previous call to the DescribeSecurityGroups operation. Leave this parameter empty the first time you call this operation.

MaxResults Integer No 10

The maximum number of entries to return on each page. If you specify the MaxResults parameter, both the MaxResults and NextToken parameters are used for a paged query.

Maximum value: 100.

Default value: 10.

Response parameters

Parameter Type Example Description
PageSize Integer 10

The number of entries returned on each page.

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

The page number of the returned page.

Note This parameter will be deprecated in the future. We recommend that you use the NextToken and MaxResults parameters for a paged query.
RequestId String 473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

The ID of the request.

TotalCount Integer 20

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

RegionId String cn-hangzhou

The region ID of the security group.

SecurityGroups Array of SecurityGroup

Details about the security groups.

SecurityGroup
CreationTime String 2021-08-31T03:12:29Z

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

VpcId String vpc-bp67acfmxazb4p****

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

ServiceManaged Boolean false

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

Description String TestDescription

The description of the security group.

SecurityGroupId String sg-bp67acfmxazb4p****

The ID of the security group.

ResourceGroupId String rg-bp67acfmxazb4p****

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

SecurityGroupName String SGTestName

The name of the security group.

EcsCount Integer 0
Note This parameter is in invitational preview and is unavailable.
ServiceID Long 12345678910

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

SecurityGroupType String normal

The type of the security group. Valid values:

  • normal: basic security group
  • enterprise: advanced security group
AvailableInstanceAmount Integer 0
Note This parameter is in invitational preview and is unavailable.
Tags Array of Tag

The tags of the security group.

Tag
TagValue String TestValue

The tag value of the security group.

TagKey String TestKey

The tag key of the security group.

NextToken String e71d8a535bd9cc11

The query token returned in this call. If the return value of this parameter is empty when MaxResults and NextToken are used for a paged query, no more results are to be returned.

Examples

Sample requests

http(s)://ecs.aliyuncs.com/?Action=DescribeSecurityGroups
&RegionId=cn-hangzhou
&MaxResults=10
&Common request parameters

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

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

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

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

Error codes

HttpCode Error code Error message Description
400 NotSupported.PageNumberAndPageSize The parameters PageNumber and PageSize are currently not supported, please use NextToken and MaxResults instead. The error message returned because the PageNumber and PageSize parameters are not available. Use the NextToken and MaxResults parameters instead.
500 InternalError The request processing has failed due to some unknown error. The error message returned because an internal error has occurred. Try again later.

For a list of error codes, see Service error codes.