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

(aws-cdk): Allow CLI to reuse cdk.out on subsequent commands #32244

Closed
1 of 2 tasks
hanseltime opened this issue Nov 22, 2024 · 4 comments
Closed
1 of 2 tasks

(aws-cdk): Allow CLI to reuse cdk.out on subsequent commands #32244

hanseltime opened this issue Nov 22, 2024 · 4 comments
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 package/tools Related to AWS CDK Tools or CLI

Comments

@hanseltime
Copy link

Describe the feature

When I call cdk <action>, I should have the option (non-default) to tell the cdk to use the existing CloudAssembly in the output directory.

Example:

cdk synth
# This command would skip all of the CloudAssembly synthesis time because it would just load what is there
cdk diff --reuse-out -e my-stackA

Use Case

Currently, if I run cdk synth and then cdk diff stack-a or cdk deploy, etc. The entire CDK app is rendered out completely before the actual diff or deploy function is done. As a default state, I have no issue with this, since that guarantees that I didn't change any CDK code and have stale output.

However, with growing CDK apps (especially those that might write a lot of data, like EKS clusters with manifests or dashboard templates), running multiple cdk commands becomes an expensive chore (we're talking up to 5-10 minutes of additional lost time given larger grouping). For both controlled CD environments (where I may want to run synth, maybe output a diff, and then deploy) and local development/troubleshooting (where you might want to run many separate stack diffs as you verify something), it would be very helpful to have a top-level flag like: --reuse-out, that would allow subsequent calls to operate on the same output from a previous synth step.

Proposed Solution

I have implemented something like this already, albeit in a very hacked way.

Ideally, we would just update the cli.js file aws-cdk to:

  1. consume the 'reuse-out` flag
  2. in the default synthesizer of the CloudExecutable, perform a lookup of the out directory and just use cxapi.CloudAssembly to load the assembly and return without re-running the execProgram() function

As a matter of safety, we would write out a warning to console to notify that we are doing this, and we could even print a summary of stacks, etc. for a double check. I think by making this feature opt-in, the developer is taking an active role in double-checking when they call it.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.169.0

Environment details (OS name and version, etc.)

mac and pop_os

@hanseltime hanseltime added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Nov 22, 2024
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Nov 22, 2024
@floverfelt
Copy link

@hanseltime if you specify the --app flag, you can skip the synthesis: https://docs.aws.amazon.com/cdk/v2/guide/cli.html#cli-app-command

"When deploying, you may also specify a directory containing synthesized cloud assemblies, such as cdk.out, as the value of --app. The specified stacks are deployed from this directory; the app is not synthesized."

We do:

cdk --app cdk.out deploy

which sped up our deployments quite a bit when the templates were already synthed. I'm not sure if that would work with diff.

@ashishdhingra
Copy link
Contributor

https://docs.aws.amazon.com/cdk/v2/guide/cli.html#cli-app-command

@floverfelt Nice call out.

@hanseltime Please verify if it works for you.

Thanks,
Ashish

@ashishdhingra ashishdhingra added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Nov 22, 2024
@hanseltime
Copy link
Author

@floverfelt - I have no idea how I've missed that. That does indeed load the CloudAssembly without rebuilding it in the commands (including diff)!

Thank you and my apologies for creating a feature request that already exists.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Nov 23, 2024
@ashishdhingra ashishdhingra closed this as not planned Won't fix, can't repro, duplicate, stale Nov 23, 2024
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

3 participants