-
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
(aws-cdk:cli): Cross-stack dependencies should be handled more gracefully #27420
Comments
It sounds like your proposed solution is to only remove an export if it's detected that the export is not currently being used by any other stacks in your app after deployment? This would take a great engineering effort to work around the current design
I'm not finding this behavior on the latest version, when I followed these steps the CDK deleted the Lambda Stack first. Not to say that cross-stack dependencies don't have their issues at times regarding imports/exports, but I'm not sure your proposed solution is a direction we would go |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Here's a reproduction using the latest CDK version: https://github.com/ajhool/cdk-dependency-issue The cdk source code contains a message detailing this issue's behavior and explaining why aws-cdk/packages/aws-cdk-lib/core/lib/stack.ts Line 1156 in 06bea31
I do run into this problem frequently and consider it to be the most annoying thing about the CDK deployment and CICD experience.
I don't think that is what I'm suggesting. I'm not suggesting to run commands after deployment. I'm suggesting that when If there isn't a caching mechanism or a simple way to do that then I'm not suggesting a major CDK rewrite for this feature. Another approach could be to notify the user of the list of "exportValues" that are autogenerated so that it's easier for the user to add that list into the Another approach would be for CDK to simply never delete those exportedValues unless the user sets a flag to delete them during |
Describe the feature
Summary: cross-stack dependencies cause a lot of headaches when designing multi-stack apps and when removing dependent resources
The main issue discussing the problem and current solution is here: #3414
The current solution of hardcoding the export value still feels unnecessarily complicated.
I believe that the main problem is that CDK is too aggressive in deleting the exportedValue from the SourceStack when a developer removes the dependency in DependentStack. What's the rush? Why can't the SourceStack continue to export the exportedValue even if no downstream resources depend on it. In a subsequent deployment, if synth realizes that an autogenerated exportedValue is no longer used, it can be safely deleted.
While I recognize that there is a solution for this, it still feels like a workaround rather than the library working as expected. In CICD pipelines where the deployments are more rigid, it's awkward for developers to keep track of this and prepare PRs specifically to address this problem before merging the real PRs with their desired updates.
I labeled this a feature request because there is a workaround, but I view this behavior as a bug.
Use Case
Using a simple example where one stack creates an S3 bucket and another lambda stack depends on the S3 bucket (eg. the lambda uses the S3 bucket's name as an env variable)
Current Behavior
If I want to delete the lambdaStack or delete the lambda function then I need to first update the bucketStack with a hardcoded
exportValue(bucket.name)
. In this simple example that's straightforward, but in a more typical case to a developer it makes no sense why deleting a lambda function (maybe one lambda of 100s) in a dependent stack (maybe 1 stack of 20) requires thinking about theBucketStack
or taking action on it.Desired behavior
Suggested workflow where developers intuitively work with StackB's dependency on StackA:
Day 1
Day 2
Day 2 or 3 or 74
BucketStack
to remove the OutputValue. This might be surprising to developers because they see acdk diff
forBucketStack
but don't see any relevant code changes inBucketStack
orLambdaStack
. The developers know that this is a quirk of cross-stack dependency management in CDK.Proposed Solution
Requirements:
My guess is that currently CDK computes the exportedValues for each stack every
synth
. That would still occur, but the results would be cached somewhere (cdk.context.json??).If all dependent resources for an exportedValue are deleted (eg. LambdaStack is deleted), a flag could be set on that exportedValue metadata in the cache saying "this exportedValue is no longer neeeded".
Either a command line flag could be exposed to --deleteUnusedExportedValues so that the developer determines when to delete any stale exported values OR maybe the metadata could have a hash key and when
cdk synth
is executed some logic on the hash key could determine that all stale exported values can be safely deletedOther Information
No response
Acknowledgements
CDK version used
2.99.1
Environment details (OS name and version, etc.)
Ubuntu
The text was updated successfully, but these errors were encountered: