How can I list Amazon EBS volume or snapshot information for my Amazon EC2 instance by using the AWS CLI?

Last updated: 2022-04-27

How can I list Amazon Elastic Block Store (Amazon EBS) volume or snapshot information for my Amazon Elastic Compute Cloud (Amazon EC2) instance using the AWS Command Line Interface (AWS CLI)?

Resolution

Note: If you receive errors when running AWS CLI commands, make sure that you’re using the most recent version of the AWS CLI.

Note: Install the jq processor before running the commands.

Amazon Linux and Amazon Linux 2:

$ sudo yum install jq

For other Linux distribution installation instructions and syntax commands, see the documentation for your Linux distribution.

Find all snapshots over one month old

The following command lists all EBS snapshots using the describe-snapshots operation where the timestamp is older than one month ( --date='-1 month').

aws ec2 describe-snapshots \
    --owner-ids self \
    --query "Snapshots[?(StartTime<='$(date --date='-1 month' '+%Y-%m-%d')')].{ID:SnapshotId,Time:StartTime,Details:Description}"

List snapshots over one month old in all Regions

The following example command uses the same command as in the first example. It also loops through snapshots in all Regions using the describe-regions operation.

for REGION in $(aws ec2 describe-regions --output text --query 'Regions[].[RegionName]') ; do echo $REGION && aws ec2 describe-snapshots --owner self --region $REGION --output json --query "Snapshots[?(StartTime<='$(date --date='-1 month' '+%Y-%m-%d')')].{ID:SnapshotId,Time:StartTime,Details:Description}" ; done

Find all publicly available snapshots in an AWS account in all Regions

This example command lists all snapshots where the CreateVolumePermission Group is equal to all for all Regions.

for REGION in $(aws ec2 describe-regions --output text --query 'Regions[].[RegionName]') ; do echo "$REGION:"; for snap in $(aws ec2 describe-snapshots --owner self --output text --region $REGION --query 'Snapshots[*].SnapshotId'); do aws ec2 describe-snapshot-attribute --snapshot-id $snap --region $REGION --output text --attribute createVolumePermission --query '[SnapshotId,CreateVolumePermissions[?Group == `all`]]'; done; echo; done

The following example command lists all volumes by using the describe-volumes-modifications operation where the modification-state is set to the value of optimizing, for all Regions.

$ for REGION in $(aws ec2 describe-regions --output text --query 'Regions[].[RegionName]') ; do echo $REGION && aws ec2 describe-volumes-modifications --query 'VolumesModifications[].{VolumeID:VolumeId,TargetSize:TargetSize,OriginalSize:OriginalSize,Progress:Progress,OriginalIops:OriginalIops,TargetIops:TargetIops}' --output json --filter 'Name=modification-state,Values=optimizing' --region $REGION; done

Find all volumes not attached to any instance in all Regions

This example command lists volumes where the status is set to available for all Regions.

$ for REGION in $(aws ec2 describe-regions --output text --query 'Regions[].[RegionName]') ; do echo $REGION && aws ec2 describe-volumes --filter "Name=status,Values=available" --query 'Volumes[*].{VolumeID:VolumeId,Size:Size,Type:VolumeType,AvailabilityZone:AvailabilityZone}' --region $REGION; done

Find all volumes in the "error" state in all Regions

The following example command describes all volumes in all Regions where the status is set to error.

$ for REGION in $(aws ec2 describe-regions --output text --query 'Regions[].[RegionName]') ; do echo $REGION && aws ec2 describe-volumes --filter "Name=status,Values=error" --query 'Volumes[*].{VolumeID:VolumeId,Size:Size,Type:VolumeType,AvailabilityZone:AvailabilityZone}' --region $REGION; done

Did this article help?


Do you need billing or technical support?