I have used the following query to find all rds snapshots, that were created after a certain date:
aws rds describe-db-snapshots --db-instance-identifier db-identifier --snapshot-type awsbackup --query 'DBSnapshots[?SnapshotCreateTime>=`Date`].{DBSnapshotIdentifier:DBSnapshotIdentifier,SnapshotCreateTime:SnapshotCreateTime}.sort_by(@,&SnapshotCreateTime)' --output json
What I am trying to do now, is to limit the result to within two hours of the desired point in time, e.g. >=Date1
, but <=Date2
.
My approach so far has been try to add a second argument to the query, like so:
aws rds describe-db-snapshots --db-instance-identifier db-identifier --snapshot-type awsbackup --query 'DBSnapshots[?SnapshotCreateTime>=`Date1`<=`Date2`].{DBSnapshotIdentifier:DBSnapshotIdentifier,SnapshotCreateTime:SnapshotCreateTime}.sort_by(@,&SnapshotCreateTime)' --output json
but this results in an empty list being returned.
Is what I am trying to do here even possible, without using jq?
The answer was quite simple in the end, different query conditions can easily be combined with a && operator. So in this case, the solution was:
aws rds describe-db-snapshots --db-instance-identifier db-identifier --snapshot-type awsbackup --query 'DBSnapshots[?SnapshotCreateTime>=`Date1`&&SnapshotCreateTime<=`Date2`].{DBSnapshotIdentifier:DBSnapshotIdentifier,SnapshotCreateTime:SnapshotCreateTime}.sort_by(@,&SnapshotCreateTime)' --output json