Can we promote RDS read replica to primary using cloud formation template? - amazon-web-services

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?

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

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.

Related

AWS RDS Aurora - Cross Region Read Replica has both Write and Reader instance?

I noticed when a Cross Region Read Replica was created for my AWS Aurora cluster - it has both a Write and Reader instance (Similar to my Primary which naturally has a writer in addition to a reader instance). In the Cluster Configuration for the Cross Region Replica cluster - I can see this "Replica" cluster indeed has the Replication source tag and its correctly getting all data flowed asynchronously.
Couple of questions I need help understanding this:
should a Cross Region Replica have a Writer?
Should I write to it in case of a disaster in the source region?
I had to explicitly make the read-replica instance (in replica region) as read_only. Otherwise read-replica accepts writes to it.
Found relevant answer in AWS re:Post:
"You're replicating to a new cluster, and each cluster needs a writer
instance. It is recommended that customers apply the read_only
parameter to the replica, but by default they are able to write to
this instance. This allows for architectures where the replica is read
& writable.
https://repost.aws/questions/QUrCbnj0u4TWaz-A1uR-QDPQ/aurora-create-cross-region-read-replica-vs-add-region
I think the name "writer" is a bit misleading.
In the doc for Aurora endpoint:
A cluster endpoint (or writer endpoint) for an Aurora DB cluster connects to the current primary DB instance for that DB cluster. This endpoint is the only one that can perform write operations such as DDL statements. Because of this, the cluster endpoint is the one that you connect to when you first set up a cluster or when your cluster only contains a single DB instance. Each Aurora DB cluster has one cluster endpoint and one primary DB instance.
So the writer instance is the same entity as the primary instance of the cluster.
In the doc for Cross-Region Replication:
When you create a cross-Region read replica for Aurora MySQL by using the AWS Management Console, Amazon RDS creates a DB cluster in the target AWS Region, and then automatically creates a DB instance that is the primary instance for that DB cluster.
For cross region replication, the new cluster (writer instance) will be created.
You don't need to take care of the writer instance. For the disaster recovery, promote read replica.

Is using one Amazon Document DB replica provide fastest fail over time?

Because there is no election involved in the fail over, so when the primary is down, it will auto switch to the only one slave automatically?
The answer to your question is within the docs. https://docs.aws.amazon.com/documentdb/latest/developerguide/replication.html
Specifically :
If a failure occurs in the primary instance (AZ1), a failover is triggered, and one of the existing replicas is promoted to primary. When the old primary recovers, it becomes a replica in the same Availability Zone in which it was provisioned (AZ1). When you provision a three-instance cluster, Amazon DocumentDB continues to preserve that three-instance cluster. Amazon DocumentDB automatically handles detection, failover, and recovery of instance failures without any manual intervention.
and
You can specify Amazon DocumentDB replicas as failover targets. That is, if the primary instance fails, the specified Amazon DocumentDB replica or replica from a tier is promoted to the primary instance. There is a brief interruption during which read and write requests made to the primary instance fail with an exception. If your Amazon DocumentDB cluster doesn't include any Amazon DocumentDB replicas, when the primary instance fails, it is re-created. Promoting an Amazon DocumentDB replica is much faster than re-creating the primary instance.
Read more about fault tolerance here.
https://docs.aws.amazon.com/documentdb/latest/developerguide/db-cluster-fault-tolerance.html

Rebooting a AWS RDS Aurora master/writer also reboots the readers?

I'm trying to evaluate AWS RDS Aurora as future replacement for our local MySQL databases, but I'm noticing some strange behaviors.
I have a basic cluster with a DB master (writer) and a replica (reader). My idea was to use the reader as an always available datasource, even when the writer in unavailable. But when I'm rebooting the master, it takes down the reader as well, making the setup quite worthless.
Looking at the reader replica log, this is what happens when the it notices that the writer is down:
Does anyone know how to have a Aurora read entry point that never goes down even if the writer is offline or busy for a brief time?
Or does the write/read "out of sync" always take down the reader entry points no matter the size of the cluster?
The only way to have a replica that remains available during a reboot of the master would be to have an asynchronous replica using conventional MySQL replication -- which Aurora does support.
Aurora replication is very different than MySQL (or Galera) replication. A loss of the master necessarily triggers a reorganization of the cluster, because the individual instances don't have their own copies of the data, they share a 6-way replicated storage volume -- that's how replication can remain in the 10-20 ms time range. What's actually replicated from the master is the transaction log LSN. Replacement of a master requires one replica to be promoted, verify that the on-disk data structures are clean after taking over, and then all of the other replicas start follow it.
If the DB cluster has one or more Aurora Replicas, then an Aurora Replica is promoted to the primary instance during a failure event. A failure event results in a brief interruption, during which read and write operations fail with an exception.
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Aurora.Managing.html#Aurora.Managing.FaultTolerance
When an Aurora replica stops seeing updates from the master, it doesn't matter where the actual fault lies -- whether with the actual master or elsewhere in the infrastructure -- the replica stops serving queries because, best case, it no longer has access to authoritative data.
Where possible, zero-downtime patching appears to avoid a master restart during upgrades. Other than upgrades, there should not be a need to restart the master.

Is creating a Read Replica of another read replica supported?

Shall i create a read replica from existing read replica in aws.
Kindly give the solution for above question.
Edit: I thought you couldn't, but it turns out that it is possible for MySQL, whereas it isn't available for PostgreSQL:
There's an announcement dated Aug 2013 which says that you can create second tier read replicas to take some load off the master.
You can now create a second-tier Read Replica from an existing
first-tier Read Replica. By creating a second-tier Read Replica, you
may be able to move some of the replication load from the master
database instance to a first-tier Read Replica. Please note that a
second-tier Read Replica may lag further behind the master because of
additional replication latency introduced as transactions are
replicated from the master to the first tier replica and then to the
second-tier replica.
Regarding Postgres, on which I based my first answer, I'm positive you can't.
There are further changes. Now you can read replicas for more DBs
From: https://aws.amazon.com/rds/faqs/
Q: Can I create a Read Replica of another Read Replica?
Amazon Aurora, Amazon RDS for MySQL and MariaDB: You can create a
second-tier Read Replica from an existing first-tier Read Replica. By
creating a second-tier Read Replica, you may be able to move some of
the replication load from the master database instance to a first-tier
Read Replica. Please note that a second-tier Read Replica may lag
further behind the master because of additional replication latency
introduced as transactions are replicated from the master to the first
tier replica and then to the second-tier replica.
Amazon RDS for PostgreSQL: Read Replicas of Read Replicas are not
currently supported.

Does Amazon Aurora create a new replica if an existing one gets promoted to the primary?

If a primary Aurora DB instance dies for some reason, and an existing replica gets promoted to the new primary, does a new replica instance get created so that I end up with the same number of read replicas?
If so, how long does it take for a new replica to be spun up on average?
There are two types of read replicas:
Backup replica (also known as slave) made by AWS when you deploy Multi-AZ RDS instance. That is synchronous read replica, but you can not use it.
Read replica created by you. Those are asynchronous replicas that you can use to offload some work.
A backup replica will be promoted to master automatically, usually it takes less than a minute. And yes, AWS will create new slave for the RDS instance that's now the master. It could take from several minutes to several hours depending on your workload and DB size.
Read replicas created by you will be just switched to the new master.
AWS Aurora is AWS's database with an architecture designed for cloud computing technologies. One of it's differences is that data is stored in a storage architecture similar to S3, in a cluster volume, which is a single, utilizes solid state disk (SSD) drives and consists of copies of the data across multiple Availability Zones in a single region. That has a few advantages, such as durability and also the fact that is distributed through in entire region, not just an AZ, helping with consistency between replicas and performance.
In case you have read replicas and your Master fails, one of them will become Master without downtime.
If you don't have a read replica, a new Master instance will be created and the process is really fast. Since data is on clusterized across the region, not on the server's disk, the process is fast, but there is downtime.
As AWS says:
To increase availability, you can use Aurora Replicas as failover
targets. That is, if the primary instance fails, an Aurora Replica is
promoted to the primary instance with only a brief interruption during
which read and write requests made to the primary instance fail with
an exception. If your Aurora DB cluster does not include any Aurora
Replicas, then the primary instance is recreated during a failure
event. However, promoting an Aurora Replica is much faster than
recreating the primary instance. For high-availability scenarios, we
recommend that you create one or more Aurora Replicas, of the same DB
instance class as the primary instance, in different Availability
Zones for your Aurora DB cluster. For more information on Aurora
Replicas as failover targets, see Fault Tolerance for an Aurora DB
Cluster.
You can read more on: http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Aurora.Replication.html"