3

I'm trying to query the snapshots created after a specific date and it is returning no results. The query I am trying is below:

aws ec2 describe-snapshots --query 'Snapshots[?StartTime >= `2017-06-01`].{id:SnapshotId}' --owner-ids nnnnnnnnnnn

If I remove the --query section, all snapshots are returned, so I know it's something to do with the query.

I tried checking the JMESPath docs but there isn't much there on date manipulation. I also tried replicating the syntax in the example here to no avail.

Thanks,

Willem van Ketwich
  • 5,666
  • 7
  • 49
  • 57

2 Answers2

6

Your code example is working perfectly well for me! (With my Account ID.)

Find the date on a snapshot, then put that date in the query -- one day before and then run it again for one day after. That should help you track down the strange behaviour.

$ aws ec2 describe-snapshots --query 'Snapshots[?StartTime >= `2016-08-30`].{id:SnapshotId}' --owner-ids 123456789012
[
    {
        "id": "snap-e044d613"
    }, 
    {
        "id": "snap-f4444506"
    }
]

$ aws ec2 describe-snapshots --query 'Snapshots[?StartTime >= `2016-08-31`].{id:SnapshotId}' --owner-ids 123456789012
[]
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
0

I am a big fan of AWS CLI and jquery so I have found the easiest way to list all the snapshots created before a specific timestamp:-

aws ec2 describe-snapshots --owner self --output json | jq '.Snapshots[] | select(.StartTime > "2019-12-18")'  
manish jha
  • 43
  • 6