This topic describes how to call the DescribeSecurityGroups operation by using Alibaba Cloud CLI to query basic information about one or more security groups.

Background information

You can call the DescribeSecurityGroups operation to query basic information about the security groups that you created. We recommend that you read the description of the operation before you call the operation. For more information, see DescribeSecurityGroups.

When you call an API operation through Alibaba Cloud CLI, make sure that request parameter values of different data types are in required formats. For more information, see Parameter format overview.

Example 1: Query information about a security group based on its ID

Query information about a VPC-type security group whose ID is sg-bp1hhwq52iu5j59f****.

aliyun ecs DescribeSecurityGroups --RegionId cn-hangzhou --SecurityGroupIds '["sg-bp1i4c0xgqxadew2****"]' --NetworkType vpc --DryRun false --output cols=SecurityGroupName,Description,VpcId,Tags rows=SecurityGroups.SecurityGroup[]

Sample response:

SecurityGroupName | Description | VpcId                     | Tags
----------------- | ----------- | -----                     | ----
namedemo          | descdemo    | vpc-bp1vwnn14rqpyiczj**** | map[Tag:[map[TagKey:user TagValue:lisi]]]

Example 2: Query information about a security group that is bound with a specific tag

Query information about a security group that is bound with the user:lisi tag.

aliyun ecs DescribeSecurityGroups --RegionId cn-hangzhou --Tag.1.Key user --Tag.1.Value lisi  --NetworkType vpc --DryRun false --output cols=SecurityGroupName,Description,VpcId,Tags rows=SecurityGroups.SecurityGroup[]

Sample response:

SecurityGroupName | Description | VpcId                     | Tags
----------------- | ----------- | -----                     | ----
namedemo          | descdemo    | vpc-bp1vwnn14rqpyiczj**** | map[Tag:[map[TagKey:user TagValue:lisi]]]

Example 3: Query information about security groups based on the ID of the VPC

Query information about security groups based on the ID of the VPC where the security groups reside.

In this example, the ID of the VPC is vpc-bp1vwnn14rqpyiczj****.

aliyun ecs DescribeSecurityGroups --RegionId cn-hangzhou --VpcId vpc-bp1vwnn14rqpyiczj**** --NetworkType vpc --DryRun false --output cols=SecurityGroupId,SecurityGroupName,Tags rows=SecurityGroups.SecurityGroup[]

Sample response:

SecurityGroupId         | SecurityGroupName       | Tags
---------------         | -----------------       | ----
sg-bp1c271nqm264lwm**** | namedemo1               | map[Tag:[map[TagKey:SMC TagValue:SMC]]]
sg-bp17wst5ddz6z6un**** | namedemo2               | map[Tag:[map[TagKey:owner TagValue:zhangsan]]]
sg-bp184jyuuw0chcw4**** | namedemo3               | map[Tag:[map[TagKey:owner TagValue:zhangsan]]]
sg-bp1i4c0xgqxadew2**** | namedemo4               | map[Tag:[map[TagKey:user TagValue:lisi]]]

Example 4: Query information about security groups by page

Query information about all security groups in a region by page.

In this example, security groups in the China (Hangzhou) region are queried. The five entries on the second page are queried.

aliyun ecs DescribeSecurityGroups --RegionId cn-hangzhou --PageNumber 2 --PageSize 5 --output cols=SecurityGroupName,VpcId,Tags rows=SecurityGroups.SecurityGroup[]

Sample response:

SecurityGroupId         | SecurityGroupName  | VpcId                     | Tags
---------------         | -----------------  | -----                     | ----
sg-bp184jyuuw0chcw4**** | demoname1          | vpc-bp1vwnn14rqpyiczj**** | map[Tag:[map[TagKey:owner TagValue:zhangsan]]]
sg-bp1gbqpn1xj8tksi**** | demoname2          | vpc-bp1rr6quz3xk8dj8s**** | map[Tag:[]]
sg-bp1i4c0xgqxadew2**** | demoname3          | vpc-bp1vwnn14rqpyiczj**** | map[Tag:[map[TagKey:user TagValue:lisi]]]
sg-bp1g3mdlybfdmhm1**** | demoname4          | vpc-bp1opxu1zkhn00gzv**** | map[Tag:[]]
sg-bp178t3hp8rtahd0**** | demoname5          | vpc-bp1rr6quz3xk8dj8s**** | map[Tag:[]]