-
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
core: Conditional Stack Evaluation Based on Context Variables #31898
Comments
Hi @HeavyPablo , I'm not 100% sure if this solves your problem, as I haven't tested it specifically for your use case, but there does exist an option Example usage: cdk deploy --exclusively Stack1 -c zoneName=myZone
# Note the flag position is not important but I like to put it before the stack name just for readability I have used this from time to time, and I think it should work for what you want to do, but like I said I haven't tested it, so I don't know if it will result in true selective synthesis. Perhaps it will still attempt to synthesize all stacks for the app and break due to the missing context arguments. But try it out! You can see the documentation for it here: https://docs.aws.amazon.com/cdk/v2/guide/ref-cli-cmd-deploy.html#ref-cli-cmd-deploy-options-exclusively |
@HeavyPablo , Thanks for reaching out. We have had similar request created by users in the past and the corresponding solutions has been provided , from time to time. I am sharing few issues with the suggested solutions -
// bin/cdk.ts
if (process.env.ENV=='prod') {
new SomeStack(app, "ProdStack");
} else {
new SomeStack(app, "DevStack");
} Reference on context variable - https://docs.aws.amazon.com/cdk/v2/guide/get_context_var.html let me know if this is helpful. |
@nicholaschiasson and @khushail Thanks! The context key Until now, I was managing this by adding another context key, for example: |
@HeavyPablo that's good to know. Should I close this one now ? |
@khushail If you can close the issue, that would be great. Thanks again! |
Comments on closed issues and PRs are hard for our team to see. |
Describe the feature
I'm proposing a feature that allows selective evaluation and synthesis of stacks based on provided context variables, making it easier to deploy individual stacks in a multi-stack environment without the need to evaluate or synthesize the entire CDK app.
This feature would give developers the option to conditionally process only the stack they intend to deploy, avoiding errors related to missing context values required by other stacks.
Use Case
As a developer, I'm often frustrated when deploying specific stacks in a multi-stack application. Even if I only need to deploy Stack1, CDK still evaluates Stack2, causing failures if
Stack2
requires context values that are not relevant to the current deployment. For example:Stack1
uses a context variablezoneName
, butStack2
usescertificate
.cdk deploy Stack1 -c zoneName=myValue
, the deployment fails becauseStack2
requirescertificate
, even though I don't want to deploy or evaluateStack2
in this step.This creates an inefficient and frustrating workflow where developers need to pass unnecessary dummy values for context or handle extra logic in code to avoid these issues.
The new feature would prevent stacks from being evaluated at all unless they are explicitly targeted for deployment.
Proposed Solution
A possible solution could be to introduce a new CLI flag, such as
--targeted-eval
or--single-stack-mode
, which would prevent the evaluation of any stacks not specified in the command.Here’s a possible workflow:
cdk deploy Stack1 --targeted-eval -c zoneName=myValue
.Stack1
, skippingStack2
entirely.Alternatively, this feature could automatically detect missing context values and only evaluate stacks that have the context provided, offering a smoother user experience.
Example:
Other Information
Additional features like warnings about "context value not provided" (without failing the entire deploy) would further improve this workflow.
Acknowledgements
CDK version used
2.164.0
Environment details (OS name and version, etc.)
Ubuntu 22.04.5 LTS
The text was updated successfully, but these errors were encountered: