View a markdown version of this page

Use ListGroupResources with a CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use ListGroupResources with a CLI

The following code examples show how to use ListGroupResources.

CLI
AWS CLI

Example 1: To list all of the resources in a resource group

The following list-group-resources example lists all of the resources that are part of the specified resource group.

aws resource-groups list-group-resources \ --group-name tbq-WebServer

Output:

{ "ResourceIdentifiers": [ { "ResourceArn": "arn:aws:ec2:us-west-2:123456789012:instance/i-09f77fa38c12345ab", "ResourceType": "AWS::EC2::Instance" } ] }

Example 2: To list the resources of a specific type in a resource group

The following list-group-resources example lists all of the resources in the group that also have a resource-type of AWS::EC2::Instance.

aws resource-groups list-group-resources \ --group-name tbq-WebServer \ --filters Name=resource-type,Values=AWS::EC2::Instance

Output:

{ "ResourceIdentifiers": [ { "ResourceArn": "arn:aws:ec2:us-west-2:123456789012:instance/i-09f77fa38c12345ab", "ResourceType": "AWS::EC2::Instance" } ] }

For more information, see What are resource groups? in the AWS Resource Groups User Guide.

PowerShell
Tools for PowerShell V4

Example 1: This example lists group resources on the basis of filtered by resource type

Get-RGGroupResourceList -Filter @{Name="resource-type";Values="AWS::EC2::Instance"} -GroupName auto-yes | Select-Object -ExpandProperty ResourceIdentifiers

Output:

ResourceArn ResourceType ----------- ------------ arn:aws:ec2:eu-west-1:123456789012:instance/i-0123bc45b567890e1 AWS::EC2::Instance arn:aws:ec2:eu-west-1:123456789012:instance/i-0a1caf2345f67d8dc AWS::EC2::Instance arn:aws:ec2:eu-west-1:123456789012:instance/i-012e3cb4df567e8aa AWS::EC2::Instance arn:aws:ec2:eu-west-1:123456789012:instance/i-0fd12dd3456789012 AWS::EC2::Instance
  • For API details, see ListGroupResources in AWS Tools for PowerShell Cmdlet Reference (V4).

Tools for PowerShell V5

Example 1: This example lists group resources on the basis of filtered by resource type

Get-RGGroupResourceList -Filter @{Name="resource-type";Values="AWS::EC2::Instance"} -GroupName auto-yes | Select-Object -ExpandProperty ResourceIdentifiers

Output:

ResourceArn ResourceType ----------- ------------ arn:aws:ec2:eu-west-1:123456789012:instance/i-0123bc45b567890e1 AWS::EC2::Instance arn:aws:ec2:eu-west-1:123456789012:instance/i-0a1caf2345f67d8dc AWS::EC2::Instance arn:aws:ec2:eu-west-1:123456789012:instance/i-012e3cb4df567e8aa AWS::EC2::Instance arn:aws:ec2:eu-west-1:123456789012:instance/i-0fd12dd3456789012 AWS::EC2::Instance
  • For API details, see ListGroupResources in AWS Tools for PowerShell Cmdlet Reference (V5).