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.
Amazon RDS DB snapshots and automated backups are stored in S3. You can use the AWS Management Console, the ModifyDBInstance API, or the modify-db-instance command to manage the period of time your automated backups are retained by modifying the RetentionPeriod parameter.
This functionality exposes a Latest Restorable Time, which is the latest point in time you create the copy from. RDS usually keeps this value within 5 minutes of the current time, but if it falls behind, you will have to contact AWS support to have the problem looked into.
-s, --db-snapshot-identifier VALUE User-supplied snapshot identifier, this is the unique key that identifies a specific snapshot of a database instance. Must be 1 to 255 alphanumeric characters or underscores. -t, --snapshot-type VALUE If specified, filters the results by the specified snapshot type.
By default, Amazon RDS creates and saves automated backups of your DB instance securely in Amazon S3 for a user-specified retention period. In addition, you can create snapshots, which are user-initiated backups of your instance that are kept until you explicitly delete them.
For me, this one works:
aws rds describe-db-snapshots \ --query="max_by(DBSnapshots, &SnapshotCreateTime)"
The query parameter returns only the most recent one.
If only the Arn is needed, this one might help:
aws rds describe-db-snapshots \ --query="max_by(DBSnapshots, &SnapshotCreateTime).DBSnapshotArn" \ --output text
And all that for a specific database instance:
aws rds describe-db-snapshots \ --db-instance-identifier={instance identifier} \ --query="max_by(DBSnapshots, &SnapshotCreateTime).DBSnapshotArn" \ --output text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With