How to find latest or most recent AWS RDS snapshot?

itchy23 picture itchy23 · Jul 19, 2016 · Viewed 9.9k times · Source

I can call aws rds describe-db-snapshots --db-instance-identifier {my_db_instance} and sort all automated snapshots to find the most recently created one but I was hoping someone has a better idea out there.

Answer

hey picture hey · May 22, 2018

For me, this one works:

aws rds describe-db-snapshots \
  --query="reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0]"

The query parameter sorts them automatically and returns only the most recent one.

If only the Arn is needed, this one might help:

aws rds describe-db-snapshots \
  --query="reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0]|DBSnapshotArn" \
  --output text

And all that for a specific database instance:

aws rds describe-db-snapshots \
  --db-instance-identifier={instance identifier} \
  --query="reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0]|DBSnapshotArn" \
  --output text