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): add the dependency on proxy targets to ensure dbInstance #12237

Merged

Conversation

saudkhanzada
Copy link
Contributor

@saudkhanzada saudkhanzada commented Dec 26, 2020

availability while creating the proxy

Fixes: #11311


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

@gitpod-io
Copy link

gitpod-io bot commented Dec 26, 2020

@github-actions github-actions bot added the @aws-cdk/aws-rds Related to Amazon Relational Database label Dec 26, 2020
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice @saudkhanzada ! A few comments before I merge this in.

packages/@aws-cdk/aws-rds/test/test.proxy.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-rds/lib/proxy.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-rds/lib/proxy.ts Outdated Show resolved Hide resolved
@saudkhanzada saudkhanzada force-pushed the fix/add-dependency-for-proxy-target branch from 73e48fe to a833302 Compare December 30, 2020 17:56
@mergify mergify bot dismissed skinny85’s stale review December 30, 2020 17:56

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: a833302
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks so much for the contribution @saudkhanzada !

@mergify
Copy link
Contributor

mergify bot commented Jan 4, 2021

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

@mergify
Copy link
Contributor

mergify bot commented Jan 4, 2021

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

@mergify mergify bot merged commit 8f74169 into aws:master Jan 4, 2021
flochaz pushed a commit to flochaz/aws-cdk that referenced this pull request Jan 5, 2021
…ws#12237)

availability while creating the proxy

Fixes: aws#11311


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mergify bot pushed a commit that referenced this pull request Dec 28, 2023
#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 (#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 #25633

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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
@aws-cdk/aws-rds Related to Amazon Relational Database
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[rds] Automatic addDependency for DatabaseProxy.proxyTarget to ensure DB Instances are available
3 participants