Amazon Elastic Compute Cloud
User Guide (API Version 2013-02-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Listing and Filtering Your Resources

As part of using Amazon EC2, you might use different resources. These include images, instances, Amazon EBS volumes, and snapshots. You can get a list of some types of resource using the EC2 console. You can get a list of each type of resource using its corresponding command or API action. For example, you can list Amazon Machine Images (AMI) using ec2-describe-images or DescribeImages, and you can list instances using ec2-describe-instances or DescribeInstances.

Filters

The resulting lists of resources can be long, so you might want to filter the results to include only the resources that match certain criteria. For example, you can list only the public 64-bit Windows AMIs that use an Amazon EBS volume as the root device volumes. As another example, you can list only the Amazon EBS snapshots that have been tagged with a certain value.

You can specify multiple filter values. For example, you can list all the instances whose type is either m1.small or m1.large. The resource must match at least one of the values to be included in the resulting resource list. You can also specify multiple filters. For example, you can list all the instances whose type is either m1.small or m1.large, and that have an attached EBS volume that is set to delete when the instance terminates. The instance must match all your filters to be included in the results.

You can also use wildcards with the filter values. An asterisk (*) matches zero or more characters, and a question mark (?) matches exactly one character. For example, you can use *database* as a filter value to get all EBS snapshots that include database in the description. If you were to specify database as the filter value, then only snapshots whose description equals database would be returned. Filter values are case sensitive. We support only exact string matching, or substring matching (with wildcards).

Tip

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?\.

Listing Resources

You can list your resources using the console, command-line interface, or API actions.

AWS Management Console

You can view the most common EC2 resource types using the AWS Management 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, click the option that corresponds to the resource, such as AMIs or Instances.

    EC2 console navigation pane

Command Line Interface

Each resource type has a corresponding command that you use to list resources of that type. For example, you can use the ec2-describe-images command to list your images, and the ec2-describe-instances command to list your instances.

The following example uses ec2-describe-instances to list your instances.

PROMPT> ec2-describe-instances

The response contains information for all your instances.

API

Each resource type has a corresponding API action that you use to list resources of that type. For example, you can use the DescribeImages action to list your images, and the DescribeInstances action to list your instances.

The following example uses DescribeInstances to list your instances.

https://ec2.amazonaws.com/?Action=DescribeInstances
&AuthParams

The response contains information for all your instances.

Filtering Resources

You can filter a list of your resources using the console, command-line interface, or API actions.

AWS Management Console

You can perform some basic filtering and sorting of the most common resource types using the AWS Management Console. For additional filtering capabilities, use the command line interface or the API actions.

To list volumes in the us-east-1b Availability Zone with a status of available

  1. In the navigation pane, click Volumes.

  2. In the Viewing pane, select Detached Volumes from the drop-down list. (A detached volume is available to be attached to an instance in the same Availability Zone.)

  3. In the Viewing pane, enter us-east-1b in the search field.

  4. Any volumes that meet this criteria are displayed.

    EC2 console navigation pane

To list public 64-bit Windows AMIs backed by Amazon EBS

  1. In the navigation pane, click AMIs.

  2. In the Filter pane, select Public Images, EBS Images and Windows from the drop-down lists.

  3. Enter x86_64 in the search field.

  4. Any AMIs that meet this criteria are displayed.

    EC2 console navigation pane

Command Line Interface

You can add one or more filters to an ec2-describe-XXX command to scope the results to resources that match certain criteria. For a list of the available filters for a given EC2 resource, go to the ec2-describe-XXX topic for that resource in the Amazon Elastic Compute Cloud Command Line Reference.

Tip

If you're using the command line tools on Windows, you might need to use quotation marks as shown here.

The following example uses filters so that ec2-describe-volumes lists only volumes that are in the us-east-1b Availability Zone and have a status of available.

PROMPT> ec2-describe-volumes --filter "availability-zone=us-east-1b" --filter "status=available"

The following example uses filters so that ec2-describe-images lists only public 64-bit Windows AMIs that use an Amazon EBS volume as the root device.

PROMPT> ec2-describe-images --filter "is-public=true" --filter "architecture=x86_64" --filter "platform=windows"

The following example uses filters so that ec2-describe-instances lists only your m1.small or m1.large instances that have an attached Amazon EBS volume that is set to delete on instance termination.

PROMPT> ec2-describe-instances --filter "instance-type=m1.small" --filter "instance-type=m1.large" --filter "block-device-mapping.status=attached" --filter "block-device-mapping.delete-on-termination=true"

For an example of filtering resources by tags, see Tagging Your Amazon EC2 Resources.

API

You can add one or more filters to a DescribeXXX action to scope the results to resources that match certain criteria. For a list of the available filters for a given EC2 resource, go to the DescribeXXX topic for that resource in the Amazon Elastic Compute Cloud API Reference.

The following example request uses filters with DescribeVolumes to list only your volumes that are in the us-east-1b Availability Zone and have a status of available.

https://ec2.amazonaws.com/?Action=DescribeVolumes
&Filter.1.Name=availability-zone
&Filter.1.Value.1=us-east-1b
&Filter.2.Name=status
&Filter.2.Value.1=available
&AUTHPARAMS

The following example request uses filters with DescribeImages to list only public 64-bit Windows AMIs that use an Amazon EBS volume as the root device.

https://ec2.amazonaws.com/?Action=DescribeImages
&Filter.1.Name=is-public
&Filter.1.Value.1=true
&Filter.2.Name=architecture
&Filter.2.Value.1=x86_64
&Filter.3.Name=platform
&Filter.3.Value.1=windows
&AUTHPARAMS

The following example request uses filters with DescribeInstances to list only the m1.small or m1.large instances that have an attached Amazon EBS volume that is set to delete on instance termination.

https://ec2.amazonaws.com/?Action=DescribeInstances
&Filter.1.Name=instance-type
&Filter.1.Value.1=m1.small
&Filter.1.Value.2=m1.large
&Filter.2.Name=block-device-mapping.status
&Filter.2.Value.1=attached
&Filter.3.Name=block-device-mapping.delete-on-termination
&Filter.3.Value.1=true
&AUTHPARAMS

For an example of filtering resources by tags, see Tagging Your Amazon EC2 Resources.