2
votes

I thought that this would be answered quite clearly out there on the internet. But I have found no sufficient answer to when to use one type of stacks and when to use another type of stacks.

  • So the main question is what is the difference between regular stacks and nested stacks?

I can perfectly model my infrastructure using only regular stacks. Also, I can perfectly model my infrastructure using only nested stacks and one root regular stack. From a project perspective - the only difference is stack type names. Everything else is the same.

For example, I am using AWS CDK - a synthesizer that can, for example, synthesize python to CloudFormation templates. I can do everything using Stacks and I can simply find-and-replace Stack to NestedStack. The infrastructure would be redeployed but nothing essentially has changed.

  • So why would I use nested stack over a regular stack? What are their own advantages?
3
I'm not sure I understand this question. Nested stacks allow you to compose together stacks. I.e. you can refactor common infrastructure templates and use it in many other stacks. If you don't need that, don't use itdpwr
Hey @dpwrussell. Thanks for the answer. That is the problem with "If you don't need that, don't use it.". I don't know if I don't need it. So you say nested stacks allow you to compose together stacks. But you can compose stacks with regular stacks too.Laimonas Sutkus
No you can't, if you nest a stack in your template, then you are using nested stacksdpwr

3 Answers

1
votes

The biggest "difference" with nested stacks is that they become part of the parent stack. This means that if anything fails to deploy all stacks (parent and nested) get rolled back as one. By contrast with multiple stacks you could have the first one succeed to deploy, the second fail and roll back and the third not even attempt a deployment.

0
votes

Nested stacks are like functions in your code, which bundle re-usable code and which you can parametrized.

Like programing in python, you can defined a method, which provides a functionality which you use across your entire application or different applications. Off course, you could just not used any methods in your python code, and just copy-and-paste the same code across multiple locations, and it would also work and be fine.

Just like functions in python, nested stacks allow you to reduce the amount of copy-and-paste across your various templates, as you can bundle common patterns into nested stacks. Just like functions, the nested stacks can be parametrized, so you can create resources from a single nested stack tailored to your needs.

why would I use nested stack over a regular stack?

To avoid copy-and-paste of the same functionality across multiple stacks. The answer is similar to "why I should use functions in python, if I can just copy-and-paste the same code everywhere when its needed?".

0
votes

So why would I use nested stack over a regular stack? What are their own advantages?<<

The main reason is if you have over 500 resources in a stack, you have no choice but to break it apart into nested stacks. This limit of 500 used to be 200 resources until a Oct 2020.