-
Notifications
You must be signed in to change notification settings - Fork 4k
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(core): dependencies across stack boundaries of all kinds #5211
Conversation
When adding dependencies of any kind (`node.addDependency`, `stack.addDependency` or `cfnResource.addDependsOn`), we now take nested stacks into account and transfer the dependency to the lowest common scope (either a common stack or the assembly). This is primarily implemented in `cfnResource.addDependsOn` and `stack.addDependency` through the following algorithm: - Lookup the lowest common stack - If not found, apply the dependency at the assembly level (between two top-level stacks). - If found, identify the two CloudFormation resources which represent this relationship within the scope of the common stack (this could be the actual resource if they are both in the same stack or the `AWS::CloudFormation::Stack` resource if the source or target are with in a nested stack). - Apply the dependency at the CloudFormation level (add `DependsOn`). There are a bunch of edge cases as well. To be able to find the AWS::CloudFormation::Stack resource for nested stacks, the `nestedStackResource` property was added to `core.Stack` and assigned by `NestedStack`. It seems like we should probably move `NestedStack` from the `aws-cloudformation` module and into `core` since there is too much coupling right now. Created a thorough test suite to examine various cases under `test.deps.ts`. Note that this suite includes tests for nested stacks and for regular cases, but decided to put them all in a single suite to make it easier to reason about coverage. Fixes #4460
Thanks so much for taking the time to contribute to the AWS CDK ❤️ We will shortly assign someone to review this pull request and help get it
|
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
For the record, I'm almost positive we should be able to cut down on the amount of |
- Rewrote the `addDependency` algorithm generically to support defining dependencies between two resources or two stacks. - Added a cache for `Stack.of` which is expected to have some nice gains since this method is widely used, especially around these algorithms.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request is now being automatically merged. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
stack.addDependency
can now be called between any two stacks in the app and the dependency will be applied at the right scope, either between top-level stacks at the assembly (app) level or betweenAWS::CloudFormation::Stack
resources that represent nested stacks in a common stack.Similarly,
cfnResource.addDependsOn
can now be called for any twoCfnResource
s in the app, and thew dependency will be applied at the right scope (either between the two resources directly, between nested stack resources or at the assembly/app level).This is implemented generically for both resources and stacks in
deps.ts/addDependency
through the following algorithm:AWS::CloudFormation::Stack
resource if the source or target are with in a nested stack).DependsOn
).To be able to find the
AWS::CloudFormation::Stack
resource for nested stacks, thenestedStackResource
property was added tocore.Stack
and assigned byNestedStack
Created a thorough test suite to examine various cases under
@aws-cdk/aws cloudformation/test.deps.ts
. Note that this suite includes tests for nested stacks and for regular cases, but decided to put them all in a single suite to make it easier to reason about coverage.This change also introduces a cache for
Stack.of(x)
by attaching the result tox
via a hidden property. This method is widely used and the cache hit rate is quite large (at the time of this writing, @aws-cdk/core unit tests hit this cache 1,112 times, @aws-cdk/aws-cloudformation unit tests hit this 2,435 times).Fixes #4406
Fixes #4474