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

fix(rds): circular dependencies when creating multiple DatabaseProxies #28471

Merged
merged 7 commits into from
Dec 28, 2023

Conversation

sakurai-ryo
Copy link
Contributor

@sakurai-ryo sakurai-ryo commented Dec 22, 2023

Description

The related issue reports that deployment fails due to circular dependencies when multiple RDSProxy are created.
The DatabaseProxy uses the node.addDependency method to ensure that the CfnDBProxyTargetGroup is created after the DBCluster and DBInstance are created (#12237).

This works well for a single DatabaseProxy, but does not work well when multiple DatabaseProxy are created with DatabaseCluster.addProxy.
When creating a DatabaseProxy with the DatabaseCluster.addProxy method, it is created as a child of the DatabaseCluster.

return new DatabaseProxy(this, id, {

The node.addDependency method recursively sets dependencies on child Constructs, so if multiple DatabaseProxy are created as a child of a DatabaseCluster in the construct tree, multiple DatabaseProxy dependencies on each other.
If the addProxy method is not used, the user initializes the DatabaseProxy directly and it does not become a child of DatabaseCluster.
For example,

new DatabaseProxy(stack, 'DBProxy', {
  proxyTarget: rds.ProxyTarget.fromCluster(cluster),
  vpc,
});

I believe this is the cause of the these resources have a dependency cycle error reported in the related issue.

To correct this error, this PR uses CfnResource.addDependency instead of node.addDependency to avoid recurrent dependencies.

Closes #25633


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team December 22, 2023 16:39
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p1 valued-contributor [Pilot] contributed between 6-12 PRs to the CDK labels Dec 22, 2023
@sakurai-ryo sakurai-ryo marked this pull request as ready for review December 22, 2023 17:30
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 22, 2023
@kaizencc kaizencc changed the title fix(rds): fix circular dependencies when creating multiple DatabaseProxy fix(rds): circular dependencies when creating multiple DatabaseProxies Dec 28, 2023
Copy link
Contributor

mergify bot commented Dec 28, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 6a0f1e7
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit a12d9eb into aws:main Dec 28, 2023
9 checks passed
Copy link
Contributor

mergify bot commented Dec 28, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

paulhcsun pushed a commit to paulhcsun/aws-cdk that referenced this pull request Jan 5, 2024
aws#28471)

### Description
The related issue reports that deployment fails due to circular dependencies when multiple RDSProxy are created.
The `DatabaseProxy` uses the `node.addDependency` method to ensure that the `CfnDBProxyTargetGroup` is created after the `DBCluster` and `DBInstance` are created (aws#12237).

This works well for a single `DatabaseProxy`, but does not work well when multiple `DatabaseProxy` are created with `DatabaseCluster.addProxy`.
When creating a `DatabaseProxy` with the `DatabaseCluster.addProxy` method, it is created as a child of the `DatabaseCluster`.
https://github.com/aws/aws-cdk/blob/cd54c4239ec29182e30fd91634505df560d6e5f8/packages/aws-cdk-lib/aws-rds/lib/cluster.ts#L446

The `node.addDependency` method recursively sets dependencies on child Constructs, so if multiple `DatabaseProxy` are created as a child of a `DatabaseCluster` in the construct tree, multiple `DatabaseProxy` dependencies on each other.
If the `addProxy` method is not used, the user initializes the `DatabaseProxy` directly and it does not become a child of `DatabaseCluster`.
For example,
```ts
new DatabaseProxy(stack, 'DBProxy', {
  proxyTarget: rds.ProxyTarget.fromCluster(cluster),
  vpc,
});
```

I believe this is the cause of the `these resources have a dependency cycle` error reported in the related issue.

To correct this error, this PR uses `CfnResource.addDependency` instead of `node.addDependency` to avoid recurrent dependencies.

Closes aws#25633

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/medium Medium work item – several days of effort p1 pr/needs-maintainer-review This PR needs a review from a Core Team Member valued-contributor [Pilot] contributed between 6-12 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RDS Proxy: adding multiple proxies via addProxy causes a circular dependency in the generated target groups
3 participants