Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CLI - How to query snapshots created after a specific date

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,

like image 334
Willem van Ketwich Avatar asked Oct 15 '25 14:10

Willem van Ketwich


1 Answers

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
[]
like image 149
John Rotenstein Avatar answered Oct 17 '25 09:10

John Rotenstein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!