aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

aws-rds - Impossible to define a DatabaseInstanceReadReplica from a DatabaseCluster

Open grifx opened this issue 6 years ago • 7 comments

Aurora Cluster Replication

I'm trying to create a cross-region read replica from an Aurora Cluster.

How can I provide a sourceDatabaseInstance from a DatabaseCluster instance?

https://docs.aws.amazon.com/cdk/api/latest/docs/aws-rds-readme.html

const cluster = new DatabaseCluster(this, 'database-cluster', props);

const readReplica = new DatabaseInstanceReadReplica(this, 'read-replica', {
  sourceDatabaseInstance: ???
})

Environment

  • CDK CLI Version: 1.22.0
  • Module Version: 1.15.0
  • OS: OSX Mojave
  • Language: TypeScript

Other information

Ideally, the cluster object could provide us with its replica database instances.

Alternatively, we could compute the instance Arn from cluster.instanceIdentifiers and change the signature of the DatabaseInstanceReadReplicaProps from readonly sourceDatabaseInstance: IDatabaseInstance; to readonly sourceDatabaseInstanceArn: string;

Thanks,

grifx avatar Feb 01 '20 05:02 grifx

DatabaseInstanceReadReplica - as the name suggests is intended to create a database instance as a replioca of another DatabaseInstance. It leverages RDS' support to create a read replica.

From what I see in the documentation, RDS does not support creating a DB instance replica from a DB cluster.

Is there something else you're looking for?

nija-at avatar Mar 26 '20 13:03 nija-at

Closing this since no response for a while now. Please re-open when you have more information here.

nija-at avatar Apr 03 '20 13:04 nija-at

@nija-at thats interesting as I am reading this:

Two Aurora MySQL DB clusters in different AWS Regions, by creating an Aurora Read Replica of an Aurora MySQL DB cluster in a different AWS Region

and also CfnDBCluster exposes sourceDbClusterIdentifier

edit: the current solution btw (if needed) is cast to CfnDBCluster and add the source that way as seen here (kotlin example):

val addSourceRds = myRdsCluster.node.defaultChild as CfnDBCluster? addSourceRds!!.sourceDbClusterIdentifier = RdsStack!!.masterCluster!!.clusterIdentifier

nzspambot avatar May 27 '20 06:05 nzspambot

edit: the current solution btw (if needed) is cast to CfnDBCluster and add the source that way as seen here (kotlin example):

val addSourceRds = myRdsCluster.node.defaultChild as CfnDBCluster? addSourceRds!!.sourceDbClusterIdentifier = RdsStack!!.masterCluster!!.clusterIdentifier

Anybody have a TypeScript example of how to create a cross-region read replica from an Aurora cluster?

This gives an error: Property AllocatedStorage cannot be empty. in CDK version 1.111.0.

const cluster = new DatabaseCluster(this, 'database-cluster', props);

const readReplica = new DatabaseInstanceReadReplica(this, 'read-replica', {
  sourceDatabaseInstance: cluster
})

AustinMaddox avatar Jul 12 '21 19:07 AustinMaddox

Hey @AustinMaddox ,

the types in your code don't match - DatabaseInstanceReadReplica needs an IDatabaseInstance passed through the sourceDatabaseInstance property, which DatabaseCluster is not (it's a Cluster after all, not an Instance 🙂).

Thanks, Adam

skinny85 avatar Jul 12 '21 20:07 skinny85

Thanks @skinny85 I do realize that fact. I guess the real problem is there isn't a construct that exists for what I'm trying to do. I imagine it would be called DatabaseClusterReadReplica rather than DatabaseInstanceReadReplica if it did exist.

Any alternatives or workaround to create a read replica of a cluster (or member instance writer/reader of a cluster)?

AustinMaddox avatar Jul 12 '21 20:07 AustinMaddox

I'm not sure. Do you know how would you set it up using CloudFormation by any chance?

skinny85 avatar Jul 12 '21 22:07 skinny85