Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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?


  • 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:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

TLaddcommented, Feb 5, 2021

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.

rmsycommented, Jul 27, 2021

For anyone who may be interested in doing something similar, here’s what I have done:

const stackBuildTargetAcct = process.env.STACK_BUILD_TARGET_ACCT || "dev";

if (stackBuildTargetAcct === "dev") {
  // define dev account stacks
} else if (stackBuildTargetAcct === "prod") {
  // define prod account stacks

Then you can just set the value of the STACK_BUILD_TARGET_ACCT environment variable appropriately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create an app with multiple stacks - AWS Documentation
Most of the code examples in the AWS CDK Developer Guide involve only a single stack. However, you can create apps containing any...
Read more >
Implement Dynamic Multi Stack (K stacks) using only one Data ...
In this article, we will see how to create a data structure that can handle multiple stacks with growable size. The data structure...
Read more >
How to create a multiple stack AWS CDK (Python ... - ITNEXT
This project has 2 different stacks, one for serverless application and another for containerized application. How to run this AWS CDK Project.
Read more >
Is there a best practice to deploy multi stack to one server ...
I have been working on MEAN stack project and intend to make a deployment. To save cost, I'm going to deploy it all...
Read more >
Multi-Stack Deployments with CDK for Terraform - YouTube
Join Daniel Schmidt (@DSchmidt1992), Sarah MacDonald, and J. Cole Morrison (@jcolemorrison) in learning about Multi-Stack Deployments with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found