edit-icon download-icon

How to query the list of associated instance IDs in a security group in the specified region?

Last Updated: Oct 08, 2016

You can run the script below on Alibaba Cloud CLI to query the list of associated instance IDs in a security group in the specified region.

  1. aliyuncli ecs DescribeInstances --RegionId cn-hangzhou --SecurityGroupId "sg-*****" --output json --filter Instances.Instance[*].InstanceId | sed '1d' | sed '$d' | sed 's/,//g' | sed 's/"//g'| sed 's/ //g'

Description:

  1. You can use the RegionId parameter to switch between regions of the security groups.

  2. You can use the SecurityGroupId parameter to specify the security group to be queried.

  3. The filter and sed parameters are used for data filtering and formatting in order to show only instance IDs in the query result.

Sample output:

  1. # aliyuncli ecs DescribeInstances --RegionId cn-hangzhou --SecurityGroupId "G44404" --output json --filter Instances.Instance[*].InstanceId | sed '1d' | sed '$d' | sed 's/,//g' | sed 's/"//g'| sed 's/ //g'
  2. i-23qv4xsw2
  3. i-23akjy3s2

If the problem persists, contact Alibaba Cloud After-Sales Technical Support.

Thank you! We've received your feedback.