8000 rds: Bug in writer/reader definition of clusters · Issue #30260 · aws/aws-cdk · GitHub
[go: up one dir, main page]

Skip to content
rds: Bug in writer/reader definition of clusters #30260
@lucabrunox

Description

@lucabrunox

Describe the bug

When creating a fresh cluster with readers and writer, one of the reader instances is effectively created before the writer and becomes the actual writer. So the opposite of what's written in the CDK code happens. This is a bug and it's reproducible.

Expected Behavior

The expected behavior is that the writer specified in CDK is indeed the writer when the cluster is created.

Current Behavior

The current behavior is that the writer becomes the reader, and viceversa, on a fresh cluster creation, which is the opposite of what's specified in CDK.

The CDK puts the writer instance first in CloudFormation, but that's not enough to guarantee that the first instance being created in the cluster because CloudFormation creates resources in parallel.

Reproduction Steps

Code:

import { App, RemovalPolicy, Stack, StackProps } from 'aws-cdk-lib';
import { InstanceClass, InstanceSize, InstanceType, SubnetType, Vpc } from 'aws-cdk-lib/aws-ec2';
import {
  AuroraMysqlEngineVersion,
  ClusterInstance,
  Credentials,
  DatabaseCluster,
  DatabaseClusterEngine,
} from 'aws-cdk-lib/aws-rds';

export class RDSReproduceStack extends Stack {
  constructor(parent: App, id: string, props: StackProps, vpc: Vpc) {
    super(parent, id, props);

    const cluster = new DatabaseCluster(this, 'testcluster', {
      clusterIdentifier: 'testcluster',
      engine: DatabaseClusterEngine.auroraMysql({ version: AuroraMysqlEngineVersion.VER_3_04_1 }),
      credentials: Credentials.fromGeneratedSecret('myuser', {}),
      writer: ClusterInstance.provisioned('writer', {
        instanceIdentifier: 'writer',
        instanceType: InstanceType.of(InstanceClass.BURSTABLE4_GRAVITON, InstanceSize.MEDIUM),
        publiclyAccessible: false,
      }),
      serverlessV2MinCapacity: 0.5,
      serverlessV2MaxCapacity: 1.0,
      readers: [
        ClusterInstance.serverlessV2('reader', {
          scaleWithWriter: true,
          publiclyAccessible: false,
        }),
      ],
      vpc: vpc,
      vpcSubnets: {
        subnetType: SubnetType.PRIVATE_WITH_EGRESS,
      },
      removalPolicy: RemovalPolicy.DESTROY,
    });
  }
}

Result, see in the image that the writer is the reader and viceversa, on a freshly created cluster:

snap 240508161922 wxXVOsXL

Possible Solution

The possible solution is to add a dependency on the writer instance to all the reader instances here: https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-rds/lib/cluster.ts , to guarantee that the writer instance is the first instance being created in the cluster and thus become the writer.

Additional Information/Context

No response

CDK CLI Version

2.130.0

Framework Version

No response

Node.js Version

18

OS

Ubuntu

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-rdsRelated to Amazon Relational DatabasebugThis issue is a bug.effort/mediumMedium work item – several days of effortp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0