How to Test an Amazon RDS Snapshot Restore with the AWS CLI
By Jérémy Sculfort · · 5 min read
Key takeaways
- A snapshot restore always creates a new DB instance or cluster — production is never touched.
- Always pass your own subnet group, security group and parameter group: otherwise RDS falls back to the defaults.
- A restore that reaches
availableis not a test. Connect, query every table and time the whole run. - Delete the restored resources at the end, with
--skip-final-snapshot, or you keep paying for them.
Taking snapshots is the easy part of an RDS backup strategy. The hard part is knowing that a snapshot can actually be turned back into a working database, within the time your business can afford. The AWS Well-Architected Framework lists "restoring a backup, but not querying or retrieving any data" as an anti-pattern for exactly that reason. This guide walks through a complete restore test with the AWS CLI, for both RDS instances and Aurora clusters.
Before you start
You need the AWS CLI v2, permissions to describe and restore snapshots, and a place to run SQL from inside the VPC (a bastion, an EC2 instance, AWS CloudShell in a VPC or a Lambda function). Keep two rules in mind:
- Restores never overwrite. RDS cannot restore a snapshot onto an existing instance; it always creates a new one with the identifier you choose.
- Defaults are not your settings. Unless you specify them, the restored instance gets the default DB parameter group, the default option group and the default VPC, subnet group and security group.
1. Pick the snapshot to test
Test the snapshot you would really use in an incident: usually the most recent automated one.
SNAP=$(aws rds describe-db-snapshots \
--db-instance-identifier prod-db \
--snapshot-type automated \
--query 'reverse(sort_by(DBSnapshots, &SnapshotCreateTime))[0].DBSnapshotIdentifier' \
--output text)
echo "Testing $SNAP"For Aurora, use describe-db-cluster-snapshots --db-cluster-identifier with the same query on DBClusterSnapshots.
2. Prepare an isolated network
The restored copy contains production data, so treat it like production. Use private subnets in at least two Availability Zones and a security group that only accepts the database port from your test runner:
aws rds create-db-subnet-group \
--db-subnet-group-name restore-test \
--db-subnet-group-description "Isolated restore tests" \
--subnet-ids subnet-aaaa subnet-bbbbNever make the restored instance publicly accessible, and do not let it share a security group with production application servers: a test copy that applications can reach by mistake is a data-integrity incident waiting to happen.
3. Restore the snapshot
RDS instance (MySQL, PostgreSQL)
TEST_DB=restore-test-$(date +%Y%m%d%H%M)
START=$(date +%s)
aws rds restore-db-instance-from-db-snapshot \
--db-instance-identifier "$TEST_DB" \
--db-snapshot-identifier "$SNAP" \
--db-instance-class db.t4g.medium \
--db-subnet-group-name restore-test \
--vpc-security-group-ids sg-0123456789abcdef0 \
--db-parameter-group-name prod-mysql80-params \
--no-publicly-accessible \
--no-multi-az \
--tags Key=purpose,Value=restore-test
aws rds wait db-instance-available --db-instance-identifier "$TEST_DB"A smaller instance class keeps the test cheap, but if you want to measure a realistic recovery time, restore with the class you would use in an incident. Passing --tags also matters: when you don't, RDS copies the source instance's tags onto the restored copy, which can confuse cost reports and tag-based automation.
Aurora cluster
An Aurora snapshot restores into a cluster without any instance, so the restore is a two-step operation:
aws rds restore-db-cluster-from-snapshot \
--db-cluster-identifier "$TEST_DB" \
--snapshot-identifier "$SNAP" \
--engine aurora-mysql \
--db-subnet-group-name restore-test \
--vpc-security-group-ids sg-0123456789abcdef0 \
--serverless-v2-scaling-configuration MinCapacity=0.5,MaxCapacity=4
aws rds create-db-instance \
--db-instance-identifier "$TEST_DB-1" \
--db-cluster-identifier "$TEST_DB" \
--engine aurora-mysql \
--db-instance-class db.serverless
aws rds wait db-instance-available --db-instance-identifier "$TEST_DB-1"Aurora Serverless v2 is a good fit for restore tests: capacity scales with the validation queries and you only pay while the test runs.
4. Get credentials you control
The restored database keeps the master username and password of the source at snapshot time. Rather than distributing production credentials to the test environment, set a fresh password on the copy:
aws rds modify-db-instance \
--db-instance-identifier "$TEST_DB" \
--master-user-password "$(openssl rand -base64 30 | tr -dc 'A-Za-z0-9' | head -c 32)" \
--apply-immediatelyUse modify-db-cluster for Aurora. Store the password in AWS Secrets Manager for the duration of the test, and wait until the instance is available again before connecting.
5. Verify the data, not just the status
An instance in the available state proves that RDS could read the snapshot metadata. It does not prove your data is complete. At a minimum, connect and check that:
- every expected database and schema exists;
- every table can be read, with an exact row count close to production at snapshot time;
- the most recent rows (for example
max(created_at)) match the snapshot time, which confirms your recovery point objective (RPO); - a few business queries your application relies on return results.
The exact SQL for MySQL and PostgreSQL is detailed in our guide to verifying database integrity after a restore. Expect the first full reads to be slower than in production: a restored instance becomes available while it is still loading data blocks from Amazon S3 in the background (lazy loading).
6. Measure your recovery time
Record the elapsed time from the start of the restore to the end of the checks. That number is your measured RTO for this database:
END=$(date +%s)
echo "Restore + validation: $(( (END - START) / 60 )) minutes"Compare it with the RTO you promised. If a 400 GB database needs 50 minutes to restore and 30 more to warm up, a "1 hour RTO" is not realistic — better to learn that during a test than during an outage.
7. Clean up
aws rds delete-db-instance \
--db-instance-identifier "$TEST_DB" \
--skip-final-snapshot \
--delete-automated-backupsFor Aurora, delete the instance first, then the cluster with delete-db-cluster --skip-final-snapshot. Finally, delete the temporary secret. Tagging every test resource (here purpose=restore-test) lets a scheduled job find and remove anything a failed run left behind.
Common pitfalls
- Encrypted snapshots shared across accounts must use a customer managed KMS key that is shared with the target account; copy the shared snapshot into the target account, then restore the copy.
- Old engine versions: if a snapshot's engine version is no longer supported, you must upgrade the snapshot before restoring it.
- Forgotten copies: a restored db.r6g.xlarge left running for a month costs hundreds of dollars. Always clean up in a
finallystep. - One-off tests: a test done once a year proves little. Automate it so every new snapshot — or at least one per week per database — is restored and checked.
Automating the whole procedure
Scripted end to end, this procedure becomes an event-driven pipeline: an EventBridge rule on RDS snapshot events starts a Step Functions workflow that creates the network, restores, polls the status, runs the checks from a Lambda inside the VPC, writes a report and deletes everything. That is exactly what SnapshotShield deploys in your account; if you prefer to build it yourself, the steps above are the building blocks.
Sources
Automate this for every RDS snapshot
SnapshotShield restores each new snapshot in an isolated VPC in your own AWS account, checks every table and sends you a report — then cleans everything up.
Start the 14-day free trial See a sample report