3

I'm writing an AWS lambda function to take my most recent snapshot of our production database and restore it as a new DB. This worked fine as a RDS instance but we recently switched our main DB to Aurora and its a cluster not an instance.

I looked in the API and was able to repurpose the old logic. I swapped out the word instance for cluster for the most part and it looked to work, it created a new cluster, etc. The new cluster however is showing 0 instances, whereas the DB it originated from shows 1. I think this is preventing me from remote connecting to it like I can the original DB cluster.

I'm still really not sure what a cluster is but do I have to launch an instance separately to enable remote connection?

Here is part of the python script btw -

def byTimestamp(snap):
  if 'SnapshotCreateTime' in snap:
    return datetime.datetime.isoformat(snap['SnapshotCreateTime'])
  else:
    return datetime.datetime.isoformat(datetime.datetime.now())

def restore_db():
    client = boto3.client('rds', region_name=region)
    source_snaps = client.describe_db_cluster_snapshots(DBClusterIdentifier = 'main-production')['DBClusterSnapshots']
    source_snap = sorted(source_snaps, key=byTimestamp, reverse=True)[0]['DBClusterSnapshotIdentifier']

    response = client.restore_db_cluster_from_snapshot(
      DBClusterIdentifier='main-development',
      SnapshotIdentifier=source_snap,
      Port=port,
      Engine='aurora-postgresql')

2 Answers 2

4

Yes, you have to launch an instance in the cluster.

An Aurora cluster has an Aurora Storage Volume with your data, and 0 or more instances that can access it. You can't actually access a cluster's data unless you have at least 1 instance in the cluster.

The reason for this abstraction is that unlike in a conventional database server, where the data is "on the server" and where you have a master server and sometimes one or more replicas, each with a copy of the data, the Aurora master and replicas write to and read from the same storage, and any replica can be promoted to become the master if the master fails.

The console hides some of this from you, if you provision Aurora from there.

2

Here's the official AWS documentation on restore_db_cluster_from_snapshot:

Note

This action only restores the DB cluster, not the DB instances for that DB cluster. You must invoke the CreateDBInstance action to create DB instances for the restored DB cluster, specifying the identifier of the restored DB cluster in DBClusterIdentifier . You can create DB instances only after the RestoreDBClusterFromSnapshot action has completed and the DB cluster is available.

Now, you might have to add a waiter event so that your RestoreDBClusterFromSnapshot action completes before you could invoke CreateDBInstance action. See available RDS waiters for more details. If you do not find a waiter readily available, then you could create your own custom_waiter.py

2
  • How to manage this waiter in the shell using aws cli? Jan 31, 2022 at 5:20
  • Bty I am not able to create or add reader/writer even using AWS Console, Status shows creating for both reader/writer for a very long time so I even can't create DB instance using the console? Note add reader options is showing but in light color ie it is disabled or can't clicked Jan 31, 2022 at 5:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .