Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rds: Upgrade(2.142.0 -> 2.143.0) added an explicit dependency between some of our DB constructs. #30383

Open
mamta925 opened this issue May 30, 2024 · 5 comments
Assignees
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@mamta925
Copy link

Describe the bug

In CDK upgrade

Package Type Update Change
aws-cdk (source) devDependencies minor 2.142.0 -> 2.143.0
aws-cdk-lib (source) dependencies minor 2.142.0 -> 2.143.0

This upgrade added an explicit dependency between some of our DB constructs.

"DbDbClusterreaderB277327D": { "DeletionPolicy": "Delete", "DependsOn": [ "DbDbClusterwriterCE53952E", ], "Properties": { "DBClusterIdentifier": { "Ref": "DbDbCluster8FBC7FAD",

Now, cloudformation wants to delete and recreate the database in order to apply that change, which is obviously not convenient.

So… any ideas how we can deploy this change without deleting the DB and having to re-load the data?

Expected Behavior

It should not delete DB

Current Behavior

Stack update is failing because of DB recreation

Reproduction Steps

const dbCluster = new rds.DatabaseCluster(this, "DbCluster", {
  serverlessV2MinCapacity: 1,
  serverlessV2MaxCapacity: 10,
  writer: rds.ClusterInstance.serverlessV2("writer"),
  readers: [rds.ClusterInstance.serverlessV2("reader")],
  storageEncryptionKey: dbStorageEncryptionKmsKey,
  removalPolicy: RemovalPolicy.DESTROY,
  copyTagsToSnapshot: true,
  clusterIdentifier: dbName,
  securityGroups: [dbSecurityGroup],
  credentials: dbClusterCredentials,
  vpc,
  vpcSubnets: privateSubnets,
  defaultDatabaseName: dbDatabaseName,
  engine: rds.DatabaseClusterEngine.auroraMysql({
    version: rds.AuroraMysqlEngineVersion.VER_3_05_2,
  }),
});

Our old DB constuct , now updating

cdk versions

Possible Solution

not sure if this is causing issue : #30260

Additional Information/Context

No response

CDK CLI Version

aws-cdk (source) devDependencies minor 2.142.0 -> 2.143.0

Framework Version

No response

Node.js Version

20

OS

Linux

Language

TypeScript

Language Version

No response

Other information

No response

@mamta925 mamta925 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 30, 2024
@github-actions github-actions bot added the @aws-cdk/aws-rds Related to Amazon Relational Database label May 30, 2024
@colifran
Copy link
Contributor

colifran commented Jun 3, 2024

I think this PR is where the explicit dependency was added. @pahud any thoughts on this?

@pahud
Copy link
Contributor

pahud commented Jun 3, 2024

Yes that PR ensures the writer would always be created before the reader.

Hi @mamta925

Did you mean you created this in 2.142.0 and now you just tried to upgrade to 2.143.0 and CDK is trying to replace your nodes?

const dbCluster = new rds.DatabaseCluster(this, "DbCluster", {
  serverlessV2MinCapacity: 1,
  serverlessV2MaxCapacity: 10,
  writer: rds.ClusterInstance.serverlessV2("writer"),
  readers: [rds.ClusterInstance.serverlessV2("reader")],
  storageEncryptionKey: dbStorageEncryptionKmsKey,
  removalPolicy: RemovalPolicy.DESTROY,
  copyTagsToSnapshot: true,
  clusterIdentifier: dbName,
  securityGroups: [dbSecurityGroup],
  credentials: dbClusterCredentials,
  vpc,
  vpcSubnets: privateSubnets,
  defaultDatabaseName: dbDatabaseName,
  engine: rds.DatabaseClusterEngine.auroraMysql({
    version: rds.AuroraMysqlEngineVersion.VER_3_05_2,
  }),
});

@pahud
Copy link
Contributor

pahud commented Jun 3, 2024

trying to reproduce this in my account

@pahud pahud changed the title (aws-cdk): (Upgrade(2.142.0 -> 2.143.0) added an explicit dependency between some of our DB constructs.) rds: Upgrade(2.142.0 -> 2.143.0) added an explicit dependency between some of our DB constructs. Jun 3, 2024
@pahud
Copy link
Contributor

pahud commented Jun 3, 2024

Hi @mamta925

I created the cluster with 2.142.0 as below:

export class DummyStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const vpc = ec2.Vpc.fromLookup(this, 'Vpc', { isDefault: true });

    const dbCluster = new rds.DatabaseCluster(this, "DbCluster", {
      serverlessV2MinCapacity: 1,
      serverlessV2MaxCapacity: 10,
      writer: rds.ClusterInstance.serverlessV2("writer"),
      readers: [rds.ClusterInstance.serverlessV2("reader")],
      // storageEncryptionKey: dbStorageEncryptionKmsKey,
      removalPolicy: RemovalPolicy.DESTROY,
      copyTagsToSnapshot: true,
      // clusterIdentifier: dbName,
      // securityGroups: [dbSecurityGroup],
      // credentials: dbClusterCredentials,
      vpc,
      // vpcSubnets: privateSubnets,
      // defaultDatabaseName: dbDatabaseName,
      engine: rds.DatabaseClusterEngine.auroraMysql({
        version: rds.AuroraMysqlEngineVersion.VER_3_05_2,
      }),
    });

  }
}

Then I upgraded to 2.143.0. The cdk diff indicates the reader node is going to have a DependOn on the writer with in-place update and it took 10 seconds on the deployment. No node is being replaced.

image

Now, cloudformation wants to delete and recreate the database in order to apply that change, which is obviously not convenient.

What made you think CFN was trying to delete and recreate the instance?

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jun 3, 2024
@pahud pahud self-assigned this Jun 3, 2024
@mamta925
Copy link
Author

mamta925 commented Jun 5, 2024

Hey, yes this part only,
As soon as I added below code(removed dependency ) then every thing worked

   const  cfnDbReader = dbCluster.node.findChild("reader").node.defaultChild as CfnResource;
    cfnDbReader.addOverride("DependsOn", undefined);

Screenshot 2024-06-05 at 8 10 29 AM

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

3 participants