I'm currently enhancing our development process by adding temporary environments for each pull request (PR) we open. These environments share certain resources like a common RDS instance and a Redis instance. I'm trying to decide on the best CloudFormation setup for this: should I create one substack for each environment within a single root stack (with the shared resources in the root), or should I opt for one stack per environment along with a separate stack for the shared resources?
4 Answers
I think having a dedicated stack for shared resources and a separate stack for each environment is a much cleaner and safer approach. It allows each developer to deploy their PRs without running into CI/CD conflicts, which is essential.
Why not just use a single stack with variables in the template for different environments? That way you keep it simpler.
I really don't recommend going with nested CloudFormation stacks. They can turn your life into a nightmare. Just stick to a more straightforward approach to avoid the headaches.
Yeah, working with CloudFormation can be tough, and adding substacks definitely complicates things.
Can you share more about your experience? I’ve mostly used AWS CDK with nested stacks and found it okay, but I’m curious about the downsides you faced.
We chose to go with one stack per environment too. This allows us to deploy concurrently for every commit in each opened PR, which is critical for our workflow.

We actually ran into the 500 resources per stack limit, so that wasn't feasible for us.