Queries the basic information of security groups.
Usage notes
Take note of the following items:
- The basic information of security groups includes their IDs and descriptions. The response returns security groups 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 use MaxResults to specify the maximum number of entries to return in 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 perform the next request, set NextToken to the NextToken value that is returned in the previous call and use MaxResults to specify the maximum number of entries to return in this request. 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 the required formats. For more information, see Parameter format overview.
Debugging
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 of the security group. You can call the DescribeRegions operation to query the most recent list of regions. |
SecurityGroupIds | String | No | ["sg-bp67acfmxazb4p****", "sg-bp67acfmxazb4p****", "sg-bp67acfmxazb4p****",....] | The security group IDs. The value is a JSON array that consists of up to 100 security group IDs. Separate the security group IDs with commas (,). |
VpcId | String | No | vpc-bp67acfmxazb4p**** | The ID of the virtual private cloud (VPC) to which the security group belongs. |
SecurityGroupType | String | No | normal | The type of the security group. Valid values:
Note If you do not specify this parameter, both basic and advanced security groups are queried. |
NextToken | String | No | e71d8a535bd9cc11 | 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. |
MaxResults | Integer | No | 10 | The maximum number of entries per page. If you specify MaxResults, Valid values: 1 to 100. Default value: 10. |
NetworkType | String | No | vpc | The network type of the security group. Valid values:
|
SecurityGroupName | String | No | SGTestName | The name of the security group. |
IsQueryEcsCount | Boolean | No | null | Specifies whether to query the capacity of the security group. If you set this parameter to True, the Note This parameter is no longer used. |
ResourceGroupId | String | No | rg-bp67acfmxazb4p**** | The ID of the resource group to which the security group belongs. When you use this parameter to filter resources, the number of resources in the specified resource group cannot exceed 1,000. 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. |
Tag.N.key | String | No | testkey | The key of tag N of the security group. Note This parameter will be removed in the future. We recommend that you use the Tag.N.Key parameter to ensure future compatibility. |
Tag.N.Key | String | No | TestKey | The key of tag N of the security group. Valid values of N: 1 to 20. If a single tag is specified to query resources, up to 1,000 resources that have this tag added are returned. If multiple tags are specified to query resources, up to 1,000 resources that have all these tags added are returned. To query more than 1,000 resources that have the specified tags added, 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 value of tag N 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. |
DryRun | Boolean | No | false | Specifies whether to perform only a dry run, without performing the actual request. Valid Values:
Default value: false. |
SecurityGroupId | String | No | sg-bp67acfmxazb4p**** | The ID of the security group. |
FuzzyQuery | Boolean | No | null | Note This parameter is no longer used. |
PageNumber | Integer | No | 1 | 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. |
PageSize | Integer | No | 10 | 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. |
Response parameters
Parameter |
Type |
Example |
Description |
RequestId | String | 473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E | The request ID. |
RegionId | String | cn-hangzhou | The region ID of the security group. |
NextToken | String | e71d8a535bd9cc11 | The pagination token that can be used in the next request to retrieve a new page of results. If the return value of this parameter is empty when you specify MaxResults and NextToken for a paged query, no more results are to be returned. |
SecurityGroups | Array of SecurityGroup | Details about the security groups. |
|
SecurityGroup | |||
SecurityGroupId | String | sg-bp67acfmxazb4p**** | The ID of the security group. |
SecurityGroupName | String | SGTestName | The name of the security group. |
Description | String | TestDescription | The description of the security group. |
SecurityGroupType | String | normal | The type of the security group. Valid values:
|
VpcId | String | vpc-bp67acfmxazb4p**** | The ID of the VPC to which the security group belongs. |
CreationTime | String | 2021-08-31T03:12:29Z | 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. |
EcsCount | Integer | 0 | The number of private IP addresses contained in the security group. For more information, see Security group capacity. If you set IsQueryEcsCount to True, the parameter value in the response is valid. Note This parameter is no longer used. The returned quantity is for reference only. The actual quantity may differ from the returned quantity. |
AvailableInstanceAmount | Integer | 0 | The number of private IP addresses that can be added to the security group. For more information, see Security group capacity. If you set IsQueryEcsCount to True, the parameter value in the response is valid. Note This parameter is no longer used. The returned quantity is for reference only. The actual quantity may differ from the returned quantity. |
ResourceGroupId | String | rg-bp67acfmxazb4p**** | The ID of the resource group 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. |
ServiceID | Long | 12345678910 | The ID of the distributor to which the security group belongs. |
Tags | Array of Tag | The tags of the security group. |
|
Tag | |||
TagValue | String | TestValue | The value of the tag. |
TagKey | String | TestKey | The key of the tag. |
TotalCount | Integer | 20 | The total number of security groups. If |
PageNumber | Integer | 1 | The page number. Note This parameter will be removed in the future. We recommend that you use the NextToken and MaxResults parameters for a paged query. |
PageSize | Integer | 10 | The number of entries per page. Note This parameter will be removed in the future. We recommend that you use the NextToken and MaxResults parameters for a paged query. |
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
HTTP status code |
Error code |
Error message |
Description |
400 | NotSupported.PageNumberAndPageSize | The parameters PageNumber and PageSize are currently not supported, please use NextToken and MaxResults instead. | PageNumber and PageSize are not supported. Use NextToken and MaxResults instead. |
400 | InValidParameter.NextToken | The parameter NextToken is invalid. | Invalid NextToken value. |
400 | MissingParameter.RegionId | The input parameter RegionId that is mandatory for processing this request is not supplied. | RegionId is required. |
400 | InvalidParameter.SecurityGroupType | The specified SecurityGroupType is not valid. | Invalid SecurityGroupType value. |
500 | InternalError | The request processing has failed due to some unknown error. | An internal error occurred. Try again later. |
For a list of error codes, see Service error codes.