EvilVeeectorm
EvilVeeectorm

Reputation: 23

AWS cli. how to query snapshots and their name tags

first of all thanks for taking the time in helping me out on this one.

I have a 12300 long list of snapshots, working on deleting certain snapshots, so im trying to list them all first thru the CLI.

I want to get the SnapshotID, the StartTime, and from the tags, the 'Name'

I tried quite a few querys, but all of them result in null on the name :/ THsi is my latest one:

aws ec2 describe-snapshots --query 'Snapshots[*].{ID:SnapshotId,Time:StartTime,Name:Tags[?Key=='Name'].Value[*]}'

Is this something one can do? or should i query all Key pairs, and then filter them out with --filters ?

Upvotes: 2

Views: 5288

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269500

Few issues to be considered:

  • Beware of the type of quote marks around the Key Names(backticks, not single quotes)
  • Forcing a single value out of the tag array.
  • You should specify the --owner-ids otherwise all accessible snapshots will be listed (including ones that don't belong to your account)

This command works:

aws ec2 describe-snapshots --query 'Snapshots[*].{ID:SnapshotId,Time:StartTime,Name:Tags[?Key==`Name`]|[0].Value}' --owner-ids *<YOUR-ACCOUNT-ID>*

Upvotes: 4

Related Questions