'AWS CloudFormation NestedStacks vs Modules
In CloudFormation both nested stacks and modules encourage reusability by creating common components.
From the AWS documentation it is not coming out when to use what. Any suggestions?
Solution 1:[1]
Here is good experimentation with the following conclusions:
CloudFormation Modules are a good evolution of the nested stacks concept that arguably should have arrived a few years ago. And unfortunately, in their current state, they aren’t suitable for use in an enterprise—or any—environment.
So I think its better to stick with nested stacks, unless you have specific requirements to use modules.
Solution 2:[2]
The fundamental difference is that with a module you deploy a single stack for your productive resources whereas nested stack deploy 1 or many stacks at once, as the term "nested" suggests. I say "productive resources" to refer to the resources you actually want to deploy, excluding the overhead that comes with modules and nested stacks respectively.
The one thing modules and nested stacks have in common is that in both cases the underlying basic unit is just a regular stack.
Some key differences are:
- Modules are instantiated via a user defined resource type
MyOrganization::MyNamespace::MyApp::MODULE
. A nested stack is created via resource typeAWS::CloudFormation::Stack
. - Modules are native to CFN. It is an abstraction of a modularized stack stored in S3 as a .zip file. A nested stack is a plain CFN stack as YAML/JSON stored in S3. You can view your modules in the console under CloudFormation/Registry/Activated extensions/Tab "Modules" but a nested stack can only be viewed at its storage path in S3.
- Modules offer the advantage that you don't need to make your modularized stack file publicly accessible. A nested stack file must be exposed to its parent stack via a public http link to the S3 object (
TemplateURL
). - Modules are versionized via resource type AWS::CloudFormation::ModuleVersion, nested stacks are just regular stacks referencing one another and therefore there is no concept of versioning. A module version must be published first as CFN stack before deploying the module.
The official docs of AWS for CFN modules are quite sparse. The most comprehensible explanation of modules I found is this AWS blog post.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Marcin |
Solution 2 |