Reputation: 5043
I have a process that creates snapshots on a regular using a standard naming convention ended with a date-time stamp. For example "update-script-prod-08052021-075622". In a separate process, I need to identify the most recent RDS snapshot with a name like "update-script-prod". I have been experimenting with "aws rds describe-db-snapshots", but it doesn't seem to have wild card search functionality. Can someone direct me to a series of commands that can get me the latest snapshot name with a name like a value?
Upvotes: 0
Views: 854
Reputation: 36
I believe you want to utilize the JMES query system available with the AWS CLI commands. In this case, the sample query below would limit the results to the DBSnapshotIdentifiers containing the text 'update-script-prod-', and then reverse sorts those results by creation date, and returns the first one.
aws rds describe-db-snapshots --output json --query="reverse(sort_by(DBSnapshots[?contains(DBSnapshotIdentifier,'update-script-prod-')], &SnapshotCreateTime))[0]
Upvotes: 2
Reputation: 2277
You can get the latest snapshot using:
aws rds describe-db-snapshots --query="reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0]"
You should be able to combine that with with the filters argument that allows you to filter the results.
--filters Name=db-instance-id ,Values=*update-script-prod*
Upvotes: 1