This topic describes how to call the DescribeSecurityGroups operation by using Alibaba Cloud command-line interface (CLI) to query basic information about a security group.

Background information

You can call the DescribeSecurityGroups operation to query basic information about the security groups that you created. 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 basic information about a security group by using its ID

Query basic information about a security group with the network type of Virtual Private Cloud (VPC) and security group ID of 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 basic information about a security group that is bound with a specific tag

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

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 basic information about a security group by VPC ID

Query basic information about a security group based on the ID of the VPC where the security group resides.

In this example, the VPC ID 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 security group information by page

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

In this example, query information about the security groups in China (Hangzhou) on the second page and display five entries per page.

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:[]]