How to only build one stack in a multistack project?
See original GitHub issue❓ General Issue
In the documentation you can create multiple Stack
instances to have a multi-stack deployment. You can then run cdk synth <stackname>
to prepare only one stack.
However when you do this, it seems to still build all stacks. This means if I have one stack building Lambda functions in custom Docker containers, and a second stack that does virtually nothing, I have to sit through the whole build process for the stack I am not using. It also does things like VPC lookups for resources that are not in the final stack that you want to deploy.
This is a problem because I want to deploy each stack into different AWS accounts. One stack should go into the test/staging/production accounts, and the other should go into the build account where all the CodeCommit repos are. This means when I run the main stack in the prod account, it complains that the repo stack can’t find the repo permission groups (because they only exist in the build account, not in the prod/staging/test accounts). Alternatively when I run the repo stack in the build account, it complains that the main stack can’t find its VPC IDs (which doesn’t exist in the build account, only in prod/staging/test).
The Question
How can I synth/deploy only one stack in a multi-stack project, with the other stacks completely ignored and not even built, so that I can completely independently deploy each stack in a multi-stack project to a different AWS account?
Environment
- CDK CLI Version: 1.73.0
- Module Version: 1.73.0
- Node.js Version: 14.13.0
- OS: Arch Linux
- Language (Version): Javascript
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:16 (2 by maintainers)
Yep, I experience the same behavior. When I synth/deploy other stacks that have no dependencies, it bundles up lambda functions in other stacks that take awhile to run.
For anyone who may be interested in doing something similar, here’s what I have done:
Then you can just set the value of the
STACK_BUILD_TARGET_ACCT
environment variable appropriately.