This API operation is used to query a list of basic information about security groups. You can query by different parameters such as region, security group ID, and security group type.
Operation description
- Paged queries: We recommend that you use the
MaxResultsandNextTokenparameters for queries.When the response does not contain
NextToken, the current page is the last page and no more pages are available.When querying the first page, you only need to set
MaxResultsto limit the number of entries returned. TheNextTokenin the response is used as the token for querying subsequent pages.When querying subsequent pages, set the
NextTokenparameter to theNextTokenvalue obtained from the previous response as the query token, and setMaxResultsto limit the number of entries returned.
When calling the API through Alibaba Cloud CLI, the values of request parameters of different data types must follow certain format requirements. For more information, see CLI parameter format description.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
ecs:DescribeSecurityGroups |
get |
SecurityGroup
SecurityGroup
|
|
None |
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| RegionId |
string |
Yes |
The region ID. You can call DescribeRegions to query the latest region list of Alibaba Cloud. |
cn-hangzhou |
| SecurityGroupIds |
string |
No |
The list of security group IDs. A maximum of 100 security group IDs are supported at a time. The IDs are separated by commas (,) in the format of a JSON array. |
["sg-bp67acfmxazb4p****", "sg-bp67acfmxazb4p****", "sg-bp67acfmxazb4p****",....] |
| VpcId |
string |
No |
The ID of the VPC to which the security group belongs. |
vpc-bp67acfmxazb4p**** |
| SecurityGroupType |
string |
No |
The type of the security group. Valid values:
Note
If you do not specify this parameter, all types of security groups are queried. |
normal |
| NextToken |
string |
No |
The query token. Set the value to the NextToken value returned in the previous call to this operation. You do not need to set this parameter for the first call. |
e71d8a535bd9cc11 |
| MaxResults |
integer |
No |
The maximum number of entries per page for a paged query. Once this parameter is set, the query uses the combination of Maximum value: 100. Default value: 10. |
10 |
| NetworkType |
string |
No |
The network type of the security group. Valid values:
|
vpc |
| SecurityGroupName |
string |
No |
The name of the security group. |
SGTestName |
| IsQueryEcsCount |
boolean |
No |
Specifies whether to query the capacity information of the security group. When set to True, the Note
This parameter is deprecated. |
null |
| ResourceGroupId |
string |
No |
The ID of the resource group to which the security group belongs. When you use this parameter to filter resources, the number of resources cannot exceed 1000. You can call ListResourceGroups to query the list of resource groups. Note
Filtering by the default resource group is not supported. |
rg-bp67acfmxazb4p**** |
| Tag |
array<object> |
No |
The list of tags. |
|
|
object |
No |
The list of tags. |
||
| key |
string |
No |
The tag key of the security group. Note
For better compatibility, we recommend that you use the Tag.N.Key parameter. |
testkey |
| Key |
string |
No |
The tag key of the security group. Valid values of N: 1 to 20. When you use a single tag to filter resources, the number of resources with the tag cannot exceed 1000. When you use multiple tags to filter resources, the number of resources bound with all specified tags cannot exceed 1000. If the number of resources exceeds 1000, use the ListTagResources operation to query. |
TestKey |
| Value |
string |
No |
The tag value of the security group. Valid values of N: 1 to 20. |
TestValue |
| value |
string |
No |
The tag value of the security group. Note
For better compatibility, we recommend that you use the Tag.N.Value parameter. |
testvalue |
| DryRun |
boolean |
No |
Specifies whether to perform only a dry run, without performing the actual request. Valid values:
Default value: false. |
false |
| SecurityGroupId |
string |
No |
The ID of the security group. |
sg-bp67acfmxazb4p**** |
| FuzzyQuery |
boolean |
No |
Note
This parameter is deprecated. |
null |
| PageNumber |
integer |
No |
Note
This parameter is about to be deprecated. We recommend that you use NextToken and MaxResults for paged queries. |
1 |
| PageSize |
integer |
No |
Note
This parameter is about to be deprecated. We recommend that you use NextToken and MaxResults for paged queries. |
10 |
| ServiceManaged |
boolean |
No |
Specifies whether the security group is managed. Valid values:
|
false |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
|||
| RequestId |
string |
The request ID. |
473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E |
| RegionId |
string |
The region ID of the security group. |
cn-hangzhou |
| NextToken |
string |
The query token returned in this call. When you use the MaxResults and NextToken method for paged queries and this return value is empty, no more data is available. |
e71d8a535bd9cc11 |
| SecurityGroups |
object |
||
| SecurityGroup |
array<object> |
The collection of security group information. |
|
|
array<object> |
The security group information. |
||
| SecurityGroupId |
string |
The ID of the security group. |
sg-bp67acfmxazb4p**** |
| SecurityGroupName |
string |
The name of the security group. |
SGTestName |
| Description |
string |
The description of the security group. |
TestDescription |
| SecurityGroupType |
string |
The type of the security group. Valid values:
|
normal |
| VpcId |
string |
The ID of the VPC to which the security group belongs. |
vpc-bp67acfmxazb4p**** |
| CreationTime |
string |
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 |
| EcsCount |
integer |
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 |
| AvailableInstanceAmount |
integer |
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 |
| ResourceGroupId |
string |
The ID of the resource group to which the security group belongs. |
rg-bp67acfmxazb4p**** |
| ServiceManaged |
boolean |
Indicates whether the user of the security group is an Alibaba Cloud service or a distributor. |
false |
| ServiceID |
integer |
The ID of the distributor to which the security group belongs. |
12345678910 |
| Tags |
object |
||
| Tag |
array<object> |
The tags of the security group. |
|
|
object |
The tag of the security group. |
||
| TagValue |
string |
The value of the tag. |
TestValue |
| TagKey |
string |
The key of the tag. |
TestKey |
| RuleCount |
integer |
The number of rules in the security group. |
100 |
| GroupToGroupRuleCount |
integer |
The number of rules that reference security groups in the security group. |
5 |
| TotalCount |
integer |
The total number of security groups. This parameter value is not returned when you use the |
20 |
| PageNumber |
integer |
The current page number. Note
This parameter is about to be deprecated. We recommend that you use NextToken and MaxResults for paged queries. |
1 |
| PageSize |
integer |
The number of entries per page. Note
This parameter is about to be deprecated. We recommend that you use NextToken and MaxResults for paged queries. |
10 |
Examples
Success response
JSON format
{
"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"
}
]
},
"RuleCount": 100,
"GroupToGroupRuleCount": 5
}
]
},
"TotalCount": 20,
"PageNumber": 1,
"PageSize": 10
}
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. | |
| 400 | InValidParameter.NextToken | The parameter NextToken is invalid. | The specified NextToken parameter is invalid. |
| 400 | MissingParameter.RegionId | The input parameter RegionId that is mandatory for processing this request is not supplied. | The RegionId parameter is required. |
| 400 | InvalidParameter.SecurityGroupType | The specified SecurityGroupType is not valid. | The specified SecurityGroupType parameter is invalid. |
| 400 | InvalidSecurityGroupId.Malformed | The specified parameter SecurityGroupId is not valid. | The specified SecurityGroupId parameter is invalid. |
| 400 | InvalidSecurityGroupName.Malformed | The specified parameter SecurityGroupName is not valid. | The specified SecurityGroupName parameter is not valid. This parameter is empty by default. If you specify a security group name, the name must be 2 to 128 characters in length and start with a letter. It can contain letters, digits, periods (.), underscores (_), and hyphens (-) and cannot start with http:// or https. The security group name is displayed in the ECS console. |
| 500 | InternalError | The request processing has failed due to some unknown error. |
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.