Filter Amazon EC2 resources by tag - Amazon Elastic Compute Cloud

Filter Amazon EC2 resources by tag

After you add tags, you can filter your Amazon EC2 resources based tag keys and tag values.

To filter resources by tag using the Amazon EC2 console
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, select a resource type (for example, Instances).

  3. Choose the search field.

  4. In the list, under Tags, choose the tag key.

  5. Choose the corresponding tag value from the list.

  6. When you are finished, remove the filter.

For more information about using filters in the Amazon EC2 console, see Find your Amazon EC2 resources.

To filter resources by tag using the AWS CLI

The following examples show you how to use filters with the describe-instances to view instances with specific tags. All EC2 describe commands use this syntax to filter by tag across a single resource type. Alternatively, you can use the describe-tags command to filter by tag across EC2 resource types.

Example 1: Describe instances with the specified tag key

The following command describes the instances with a Stack tag, regardless of the value of the tag.

aws ec2 describe-instances \ --filters Name=tag-key,Values=Stack
Example 2: Describe instances with the specified tag

The following command describes the instances with the tag Stack=production.

aws ec2 describe-instances \ --filters Name=tag:Stack,Values=production
Example 3: Describe instances with the specified tag value

The following command describes the instances with a tag with the value production, regardless of the tag key.

aws ec2 describe-instances \ --filters Name=tag-value,Values=production
Example 4: Describe all EC2 resources with the specified tag

The following command describes all EC2 resources with the tag Stack=Test.

aws ec2 describe-tags \ --filters Name=key,Values=Stack Name=value,Values=Test