How to Restore an Aurora RDS Snapshot Using AWS CLI

Restoring an Amazon Aurora RDS snapshot allows you to recover a database to a specific point in time or create a clone for testing or…

How to Restore an Aurora RDS Snapshot Using AWS CLI
Photo by Jonathan Fink on Unsplash

Restoring an Amazon Aurora RDS snapshot allows you to recover a database to a specific point in time or create a clone for testing or development. Below is a detailed guide to restoring an Aurora RDS snapshot to an Aurora RDS Serverless cluster using the AWS Command Line Interface (CLI).

Steps to Restore an Aurora RDS Snapshot

Step 1: Identify the Snapshot

List all available snapshots to identify the one you want to restore:

aws rds describe-db-cluster-snapshots --include-shared \ 
--query "DBClusterSnapshots[*].[DBClusterSnapshotIdentifier, SnapshotCreateTime, Engine, EngineVersion, DBClusterIdentifier]" \ 
--output table

This will display a table containing:

  • Snapshot Identifier
  • Creation Time
  • RDS Engine and Engine Version
  • Cluster Identifier

Ensure you choose a snapshot with the same engine and version for restoration.

Step 2: List Available DB Subnet Groups

A DB Subnet Group determines where the Aurora RDS cluster will be deployed within your VPC. List available subnet groups:

aws rds describe-db-subnet-groups \ 
--query "DBSubnetGroups[*].DBSubnetGroupName" \ 
--output text

To use the DB Subnet Group from the snapshot’s cluster, retrieve its name:

  1. Find the snapshot’s cluster name:
aws rds describe-db-cluster-snapshots \ 
--db-cluster-snapshot-identifier "<SNAPSHOT-NAME>" \ 
--query 'DBClusterSnapshots[0].DBClusterIdentifier' \ 
--output text

2. Retrieve the associated DB Subnet Group:

aws rds describe-db-clusters \ 
--db-cluster-identifier "<CLUSTER-NAME>" \ 
--query 'DBClusters[0].DBSubnetGroup' \ 
--output text

Step 3: List Available KMS Keys

AWS KMS (Key Management Service) enables encryption for RDS clusters. Although encryption is optional, it is a security best practice. List available KMS keys:

aws kms list-aliases \ 
--query 'Aliases[].[AliasName, TargetKeyId, CreationDate]' \ 
--output table

To check the status of a specific KMS key:

aws kms describe-key --key-id <TargetKeyId> \ 
--query 'KeyMetadata.[KeyState]' \ 
--output text

Step 4: Restore the Cluster

Use the following command to restore the snapshot and create a new Aurora Serverless cluster:

aws rds restore-db-cluster-from-snapshot \ 
--db-cluster-identifier "<NEW-CLUSTER-NAME>" \ 
--snapshot-identifier "<SNAPSHOT-NAME>" \ 
--engine "<AURORA-RDS-DB-ENGINE>" \ 
--engine-version "<AURORA-RDS-DB-ENGINE-VERSION>" \ 
--db-subnet-group-name "<DB_SUBNET_GROUP_NAME>" \ 
--serverless-v2-scaling-configuration MinCapacity="<MIN_ACU>",MaxCapacity="<MAX_ACU>" \ 
--kms-key-id "<KEY-ALIAS>"
  • NEW-CLUSTER-NAME: Name for the new cluster.
  • SNAPSHOT-NAME: Snapshot identifier from Step 1.
  • AURORA-RDS-DB-ENGINE: Engine used in the snapshot (e.g., aurora-mysql).
  • MIN_ACU/ MAX_ACU: Capacity settings for the Aurora Serverless v2 cluster.

Wait for the cluster creation to complete using the following command:

aws rds wait db-cluster-available \ 
--db-cluster-identifier "<NEW-CLUSTER-NAME>"

Step 5: Create the Instance

Once the cluster is ready, create a database instance within it:

aws rds create-db-instance \ 
--db-instance-identifier "<NEW-INSTANCE-NAME>" \ 
--db-cluster-identifier "<NEW-CLUSTER-NAME>" \ 
--engine "<AURORA-RDS-DB-ENGINE>" \ 
--db-instance-class db.serverless
  • NEW-INSTANCE-NAME: Name for the new instance.

To verify the instance creation, use:

aws rds wait db-instance-available \ 
--db-instance-identifier "<NEW-INSTANCE-NAME>"

Summary of Commands

  1. Identify Snapshot:
aws rds describe-db-cluster-snapshots

2. List DB Subnet Groups:

aws rds describe-db-subnet-groups

3. List KMS Keys:

aws kms list-aliases

4. Restore Cluster:

aws rds restore-db-cluster-from-snapshot

5. Create Instance:

aws rds create-db-instance

Following these steps, you can restore an Aurora RDS snapshot and create a new Serverless cluster using the AWS CLI.

In Plain English 🚀

Thank you for being a part of the In Plain English community! Before you go: