How do I list all of my Amazon EBS snapshots with or without a specified key tag using the AWS CLI?
"I want to use the AWS Command Line Interface (AWS CLI) to list all my Amazon Elastic Block Store (Amazon EBS) snapshots. What commands are a best practice to use when I want to list all snapshots, with or without a specified tag key?"
"I want to use the AWS Command Line Interface (AWS CLI) to list all my Amazon Elastic Block Store (Amazon EBS) snapshots. What commands are a best practice to use when I want to list all snapshots, with or without a specified tag key?ResolutionNote: Before beginning this resolution, install and configure the AWS CLI.If you receive errors when running AWS CLI commands, make sure that you’re using the most recent version of the AWS CLI.List all EBS snapshots in a particular RegionThe following example command lists all EBS snapshots using the describe-snapshots operation in the Region us-east-1:aws ec2 describe-snapshots --owner-ids self  --query 'Snapshots[]' --region=us-east-1The following is example output for the describe-snapshots command:Created for policy: policy-08843cf0d7f6189ae schedule: Default Schedule    False    111122223333    100%    snap-091e33a177cb2e49b    2020-09-10T19:27:07.882Z    completed    vol-03b223394ea08e690    8TAGS    instance-id    i-0919c4d810b9c3695TAGS    dlm:managed    trueTAGS    timestamp    2020-09-10T19:27:07.548ZTAGS    aws:dlm:lifecycle-policy-id    policy-08843cf0d7f6189aeTAGS    aws:dlm:lifecycle-schedule-name    Default Scheduletest one hellop    False    111122223333    100%    snap-02faf8ffc48e512f4    2020-09-10T19:17:34.974Z    completed    vol-03b223394ea08e690    8 TAGS    ec2-console    falseCreated for policy: policy-08843cf0d7f6189ae schedule: Default Schedule    False    111122223333    100%    snap-007e74c24d8f3aaf1    2020-09-10T17:28:31.993Z    completed    vol-03b223394ea08e690    8TAGS    instance-id    i-0919c4d810b9c3695TAGS    dlm:managed    trueTAGS    aws:dlm:lifecycle-schedule-name    Default ScheduleTAGS    timestamp    2020-09-10T17:28:31.650ZTAGS    aws:dlm:lifecycle-policy-id    policy-08843cf0d7f6189aetest one     False    111122223333    100%    snap-00f20d2d2c17bbea0    2020-09-08T07:47:47.660Z    completed    vol-062b2c633c981f99e    8 TAGS    ec2-console    trueFilter the list of EBS snapshots for a specified tag keyThe following command lists EBS snapshots using the describe-snapshots operation with a specified tag key:aws ec2 describe-snapshots  --owner-ids self  --query 'Snapshots[?(Tags[?Key == `name`].Value)]'The following command lists all snapshots with the tag key ec2-console:$ aws ec2 describe-snapshots --owner-ids self --query 'Snapshots[?(Tags[?Key == `ec2-console`].Value)]'The following is an example output for the preceding command:test one hellop    False    111122223333    100%    snap-02faf8ffc48e512f4    2020-09-10T19:17:34.974Z    completed    vol-03b223394ea08e690    8 TAGS    ec2-console    falsetest one     False    111122223333    100%    snap-00f20d2d2c17bbea0    2020-09-08T07:47:47.660Z    completed    vol-062b2c633c981f99e    8 TAGS    ec2-console    trueFilter the list of EBS snapshots for snapshots that don't have a specified tag keyThe following command lists EBS snapshots that don't have a specified tag key:aws ec2 describe-snapshots --owner-ids self --query 'Snapshots[?!not_null(Tags[?Key == `name`].Value)]'The following example command filters the list of EBS snapshots for all snapshots that don't have the tag key ec2-console:$ aws ec2 describe-snapshots --owner-ids self --query 'Snapshots[?!not_null(Tags[?Key == `ec2-console`].Value)]'The following is an example output for the preceding command:Created for policy: policy-08843cf0d7f6189ae schedule: Default Schedule    False    111122223333    100%    snap-091e33a177cb2e49b    2020-09-10T19:27:07.882Z    completed    vol-03b223394ea08e690    8TAGS    instance-id    i-0919c4d810b9c3695TAGS    dlm:managed    trueTAGS    timestamp    2020-09-10T19:27:07.548ZTAGS    aws:dlm:lifecycle-policy-id    policy-08843cf0d7f6189aeTAGS    aws:dlm:lifecycle-schedule-name    Default ScheduleCreated for policy: policy-08843cf0d7f6189ae schedule: Default Schedule    False    111122223333    100%    snap-007e74c24d8f3aaf1    2020-09-10T17:28:31.993Z    completed    vol-03b223394ea08e690    8TAGS    instance-id    i-0919c4d810b9c3695TAGS    dlm:managed    trueTAGS    aws:dlm:lifecycle-schedule-name    Default ScheduleTAGS    timestamp    2020-09-10T17:28:31.650ZTAGS    aws:dlm:lifecycle-policy-id    policy-08843cf0d7f6189aeRelated informationTagging AWS resourcesFollow"