AWS CLI Describe RDS Snapshots By Status
The other day at work I had a need to use the AWS CLI to get a list of RDS snapshots (aws rds describe-db-snapshots
), but I only wanted the snapshots where Status == "available"
. In true DevOps fashion, I googled for a one-liner that I could copy/paste instead of actually learning the query syntax myself, but apparently nobody has posted it anywhere on the internet.
So if you’re in the same spot and you’re googling for “aws rds describe-db-snapshots status available” or similar, here it is:
aws rds describe-db-snapshots --query "DBSnapshots[?Status=='available']"
You can, of course, use --db-instance-identifier
too if you want to limit it to a single DB instance.
And if you’re mostly interested in automated snapshots which have a date string appended to the names, then you can pipe the results into jq
and get the last item in the array, which should be the most recent snapshot:
aws rds describe-db-snapshots --query "DBSnapshots[?Status=='available']" | jq '.[-1]'
And if you only need the snapshot ID:
aws rds describe-db-snapshots --query "DBSnapshots[?Status=='available']" | jq -r '.[-1].DBSnapshotIdentifier'