Can we promote RDS read replica to primary using cloud formation template?

2.3k Views Asked by At

We can easily promote RDS read replica using console and CLI, but is there a way to give master access means promote to primary using cloud formation?

3

There are 3 best solutions below

2
On

CloudFormation uses the property "SourceDBInstanceIdentifier" to determine whether a DBInstance is a read replica or not. If this property has any non-empty value, the DBInstance will be created as a read replica.

If you remove this property once a read replica is created and update your CloudFormation stack, a new DBInstance will be created that won't be a read replica, it will be it's own standalone database. However, the new standalone database will not have the contents of the read replica.

The solution to this will be to regularly back up your read replica. When you want to promote your read replica, remove "SourceDBInstanceIdentifier" and set "DBSnapshotIdentifier" to the most recent snapshot of the read replica. This should effectively promote your read replica to master with most the data still intact

2
On

The RDS standby replica (multi-az) will automatically be switched to master in case of failures on the master node.

How you setup the multi-az replica (could be through cloudformation) will determine the automatic switch over. Please note that the standby replica becomes the master only when there is an AZ outage, primary instance fail, software patching and not when there is scenarios of locks or database level operation timeouts.

0
On

As of 2024, we were able to promote the read replica RDS instance simply by removing the SourceDbInstanceIdentifier from CloudFormation file. The whole promotion process took no more than 5 mins.

After checking GitHub for related issue, I've bumped into this PR: https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-rds/pull/334. The support for read-replica promotion to CloudFormation was added at the end of 2022.