List and filter your resources - Amazon Elastic Compute Cloud

List and filter your resources

You can get a list of some types of resources using the Amazon EC2 console. You can get a list of each type of resource using its corresponding command or API action. If you have many resources, you can filter the results to include, or exclude, only the resources that match certain criteria.

List and filter resources using the console

List resources using the console

You can view the most common Amazon EC2 resource types using the console. To view additional resources, use the command line interface or the API actions.

To list EC2 resources using the console

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose the option that corresponds to the resource type. For example, to list your instances, choose Instances.

    The page displays all resources of the selected resource type.

Filter resources using the console

To filter a list of resources

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

  2. Choose the search field.

  3. Choose the filter from the list.

  4. Choose a filter value.

  5. When you are finished, remove the filter.

The search and filter functionality differs slightly between the old and new Amazon EC2 console.

The new console supports two types of filtering.

  • API filtering happens on the server side. The filtering is applied on the API call, which reduces the number of resources returned by the server. It allows for quick filtering across large sets of resources, and it can reduce data transfer time and cost between the server and the browser.

  • Client filtering happens on the client side. It enables you to filter down on data that is already available in the browser (in other words, data that has already been returned by the API). Client filtering works well in conjunction with an API filter to filter down to smaller data sets in the browser.

The new Amazon EC2 console supports the following types of searches:

Search by keyword

Searching by keyword is a free text search that lets you search for a value across all of your resources' attributes, without specifying an attribute to search.

Note

All keyword searches use client filtering.

To search by keyword, enter or paste what you’re looking for in the search field, and then choose Enter. For example, searching for 123 matches all instances that have 123 in any of their attributes, such as an IP address, instance ID, VPC ID, or AMI ID. If your free text search returns unexpected matches, apply additional filters.

Search by attributes

Searching by an attribute lets you search a specific attribute across all of your resources.

Note

Attribute searches use either API filtering or client filtering, depending on the selected attribute. When performing an attribute search, the attributes are grouped accordingly.

For example, you can search the Instance state attribute for all of your instances to return only instances that are in the stopped state. To do this:

  1. In the search field on the Instances screen, start entering Instance state. As you enter the characters, the two types of filters appear for Instance state: API filters and Client filters.

  2. To search on the server side, choose Instance state under API filters. To search on the client side, choose Instance state (client) under Client filters.

    A list of possible values for the selected attribute appears.

  3. Choose stopped from the list.

You can use the following techniques to enhance or refine your searches:

Inverse search

Inverse searches let you search for resources that do not match a specified value. Inverse searches are performed by prefixing the search keyword with the exclamation mark (!) character.

Note

Inverse search is supported with keyword searches and attribute searches on client filters only. It is not supported with attribute searches on API filters.

For example, you can search the Instance state attribute for all of your instances to exclude all instances that are in the terminated state. To do this:

  1. In the search field on the Instances screen, start entering Instance state. As you enter the characters, the two types of filters appear for Instance state: API filters and Client filters.

  2. Choose Instance state (client). Inverse search is only supported on client filters.

    A list of possible values for the selected attribute appears.

  3. Enter ! (exclamation mark) to display the inverse filters.

  4. Choose !terminated from the list.

To filter instances based on an instance state attribute, you can also use the search icons ( ) in the Instance state column. The search icon with a plus sign ( + ) displays all the instances that match that attribute. The search icon with a minus sign ( - ) excludes all instances that match that attribute.

Here is another example of using the inverse search: To list all instances that are not assigned the security group named launch-wizard-1, search by the Security group name attribute, and for the keyword, enter !launch-wizard-1.

Partial search

With partial searches, you can search for partial string values. To perform a partial search, enter only a part of the keyword that you want to search for. For example, to search for all t2.micro, t2.small, and t2.medium instances, search by the Instance Type attribute, and for the keyword, enter t2.

Note

Partial search is supported with keyword searches and attribute searches on client filters only. It is not supported with attribute searches on API filters.

Regular expression search

To use regular expression searches, you must enable Use regular expression matching in the Preferences.

Regular expressions are useful when you need to match the values in a field with a specific pattern. For example, to search for a value that starts with s, search for ^s. To search for a value that ends with xyz, search for xyz$. Or to search for a value that starts with a number that is followed by one or more characters, search for [0-9]+.*. Regular expression searches are not case-sensitive.

Note

Regular expression search is supported with keyword searches and attribute searches on client filters only. It is not supported with attribute searches on API filters.

Wildcard search

Use the * wildcard to match zero or more characters. Use the ? wildcard to match zero or one character. For example, if you have a data set with the following values: prod, prods, and production; "prod*" matches all values, whereas "prod?" matches only prod and prods. To use the literals values, escape them with a backslash (\). For example, "prod\*" would match prod*.

Note

Wildcard search is supported with attribute searches on API filters only. It is not supported with keyword searches and attribute searches on client filters only.

Combining searches

In general, multiple filters with the same attribute are automatically joined with OR. For example, searching for Instance State : Running and Instance State : Stopped returns all instances that are either running OR stopped. To join search with AND, search across different attributes. For example, searching for Instance State : Running and Instance Type : c4.large returns only instances that are of type c4.large AND that are in the stopped state.

The old Amazon EC2 console supports the following types of searches:

Search by keyword

Searching by keyword is a free text search that lets you search for a value across all of your resources' attributes. To search by keyword, enter or paste what you’re looking for in the search field, and then choose Enter. For example, searching for 123 matches all instances that have 123 in any of their attributes, such as an IP address, instance ID, VPC ID, or AMI ID. If your free text search returns unexpected matches, apply additional filters.

Search by attributes

Searching by an attribute lets you search a specific attribute across all of your resources. For example, you can search the State attribute for all of your instances to return only instances that are in the stopped state. To do this:

  1. In the search field on the Instances screen, start entering Instance State. As you enter characters, a list of matching attributes appears.

  2. Select Instance State from the list. A list of possible values for the selected attribute appears.

  3. Select Stopped from the list.

You can use the following techniques to enhance or refine your searches:

Inverse search

Inverse searches let you search for resources that do not match a specified value. Inverse searches are performed by prefixing the search keyword with the exclamation mark (!) character. For example, to list all instances that are not terminated, search by the Instance State attribute, and for the keyword, enter !Terminated.

Partial search

With partial searches, you can search for partial string values. To perform a partial search, enter only a part of the keyword you want to search for. For example, to search for all t2.micro, t2.small, and t2.medium instances, search by the Instance Type attribute, and for the keyword, enter t2.

Regular expression search

Regular expressions are useful when you need to match the values in a field with a specific pattern. For example, to search for all instances that have an attribute value that starts with s, search for ^s. Or to search for all instances that have an attribute value that ends with xyz, search for xyz$. Regular expression searches are not case-sensitive.

Combining searches

In general, multiple filters with the same attribute are automatically joined with OR. For example, searching for Instance State : Running and Instance State : Stopped returns all instances that are either running OR stopped. To join search with AND, search across different attributes. For example, searching for Instance State : Running and Instance Type : c4.large returns only instances that are of type c4.large AND that are in the stopped state.

List and filter using the CLI and API

Each resource type has a corresponding CLI command and API action that you use to list resources of that type. The resulting lists of resources can be long, so it can be faster and more useful to filter the results to include only the resources that match specific criteria.

Filtering considerations

  • You can specify multiple filters and multiple filter values in a single request.

  • You can use wildcards with the filter values. An asterisk (*) matches zero or more characters, and a question mark (?) matches zero or one character.

  • Filter values are case sensitive.

  • Your search can include the literal values of the wildcard characters; you just need to escape them with a backslash before the character. For example, a value of \*amazon\?\\ searches for the literal string *amazon?\.

Supported filters

To see the supported filters for each Amazon EC2 resource, see the following documentation:

Example: Specify a single filter

You can list your Amazon EC2 instances using describe-instances. Without filters, the response contains information for all of your resources. You can use the following command to include only the running instances in your output.

aws ec2 describe-instances --filters Name=instance-state-name,Values=running

To list only the instance IDs for your running instances, add the --query parameter as follows.

aws ec2 describe-instances --filters Name=instance-state-name,Values=running --query "Reservations[*].Instances[*].InstanceId" --output text

The following is example output.

i-0ef1f57f78d4775a4 i-0626d4edd54f1286d i-04a636d18e83cfacb

Example: Specify multiple filters or filter values

If you specify multiple filters or multiple filter values, the resource must match all filters to be included in the results.

You can use the following command to list all instances whose type is either m5.large or m5d.large.

aws ec2 describe-instances --filters Name=instance-type,Values=m5.large,m5d.large

You can use the following command to list all stopped instances whose type is t2.micro.

aws ec2 describe-instances --filters Name=instance-state-name,Values=stopped Name=instance-type,Values=t2.micro

Example: Use wildcards in a filter value

If you specify database as the filter value for the description filter when describing EBS snapshots using describe-snapshots, the command returns only the snapshots whose description is "database".

aws ec2 describe-snapshots --filters Name=description,Values=database

The * wildcard matches zero or more characters. If you specify *database* as the filter value, the command returns only snapshots whose description includes the word database.

aws ec2 describe-snapshots --filters Name=description,Values=*database*

The ? wildcard matches exactly 1 character. If you specify database? as the filter value, the command returns only snapshots whose description is "database" or "database" followed by one character.

aws ec2 describe-snapshots --filters Name=description,Values=database?

If you specify database????, the command returns only snapshots whose description is "database" followed by up to four characters. It excludes descriptions with "database" followed by five or more characters.

aws ec2 describe-snapshots --filters Name=description,Values=database????

Example: Filter based on date

With the AWS CLI, you can use JMESPath to filter results using expressions. For example, the following describe-snapshots command displays the IDs of all snapshots created by your AWS account (represented by 123456789012) before the specified date (represented by 2020-03-31). If you do not specify the owner, the results include all public snapshots.

aws ec2 describe-snapshots --filters Name=owner-id,Values=123456789012 --query "Snapshots[?(StartTime<='2020-03-31')].[SnapshotId]" --output text

The following command displays the IDs of all snapshots created in the specified date range.

aws ec2 describe-snapshots --filters Name=owner-id,Values=123456789012 --query "Snapshots[?(StartTime>='2019-01-01') && (StartTime<='2019-12-31')].[SnapshotId]" --output text

Filter based on tags

For examples of how to filter a list of resources according to their tags, see Work with tags using the command line.

List and filter resources across Regions using Amazon EC2 Global View

Amazon EC2 Global View enables you to view some of your Amazon EC2 and Amazon VPC resources across a single AWS Region, or across multiple Regions in a single console. Using Amazon EC2 Global View, you can view a summary of all of your VPCs, subnets, instances, security groups, and volumes across all of the Regions for which your AWS account is enabled. Amazon EC2 Global View also provides global search functionality that lets you search for specific resources or specific resource types across multiple Regions simultaneously.

Amazon EC2 Global View does not let you modify resources in any way.

Required permissions

An IAM user must have the following permissions to use Amazon EC2 Global View.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ec2:DescribeInstances", "ec2:DescribeVpcs", "ec2:DescribeRegions", "ec2:DescribeVolumes", "ec2:DescribeSubnets", "ec2:DescribeSecurityGroups" ], "Resource": "*" }] }

To use Amazon EC2 Global View

Open the Amazon EC2 Global View console at https://console.aws.amazon.com/ec2globalview/home.

The console consists of two tabs:

  • Region explorer—This tab includes the following sections:

    • Resource summary—Provides a high-level overview of your resources across all Regions.

      Enabled Regions indicates the number of Regions for which your AWS account is enabled. The remaining fields indicate the number of resources that you currently have in those Regions. Choose any of the links to view the resources of that type across all Regions. For example, if the link below the Instances label is 29 in 10 Regions, it indicates that you currently have 29 instances across 10 Regions. Choose the link to view a list of all 29 instances.

    • Resource counts per Region—Lists all of the AWS Regions (including those for which your account is not enabled) and provides totals for each resource type for each Region.

      Choose a Region name to view all resources of all types for that specific Region. For example, choose Africa (Cape Town) af-south-1 to view all VPCs, subnets, instances, security groups, and volumes in that Region. Alternatively, select a Region and choose View resources for selected Region.

      Choose the value for a specific resource type in a specific Region to view only resources of that type in that Region. For example, choose the value for Instances for Africa (Cape Town) af-south-1 to view only the instances in that Region.

  • Global search—This tab enables you to search for specific resources or specific resource types across a single Region or across multiple Regions. It also enables you to view details for a specific resource.

    To search for resources, enter the search criteria in the field preceding the grid. You can search by Region, by resource type, and by the tags assigned to resources.

    To view the details for a specific resource, select it in the grid. You can also choose the resource ID of a resource to open it in its respective console. For example, choose an instance ID to open the instance in the Amazon EC2 console, or choose a subnet ID to open the subnet in the Amazon VPC console.