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?
2 Answers
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

- 61
- 1
- 5
-
2It's a good answer but a shame that it's required. It would make far more sense that removing the source identifier would effectively promote the RR. – Alex Barnes Dec 09 '20 at 20:33
-
Feb. 2021: I checked on this with AWS support, it's still not supported, but there is a feature request in place. They suggest setting up the replica, doing the promotion via API/Console and then reimporting the newly promoted replica. – Maurice Feb 12 '21 at 10:52
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.

- 53
- 8