0
0
AWScloud~30 mins

Nested stacks for modularity in AWS - Mini Project: Build & Apply

Choose your learning style9 modes available
Nested stacks for modularity
📖 Scenario: You are building a cloud infrastructure using AWS CloudFormation. To keep your templates clean and reusable, you want to split your infrastructure into smaller parts using nested stacks.Imagine you have a main template that includes a network stack and a compute stack as nested stacks.
🎯 Goal: Create a main CloudFormation template that uses nested stacks for network and compute resources. Each nested stack should be referenced properly to keep the infrastructure modular and organized.
📋 What You'll Learn
Create a main CloudFormation template with two nested stacks: NetworkStack and ComputeStack.
Define the nested stacks using the AWS::CloudFormation::Stack resource type.
Use parameters to pass the VpcId from the network stack to the compute stack.
Ensure the nested stacks are referenced with the correct template URLs.
💡 Why This Matters
🌍 Real World
Large cloud infrastructures are often split into smaller templates to improve readability and reuse. Nested stacks allow teams to manage parts of infrastructure independently.
💼 Career
Cloud architects and DevOps engineers use nested stacks to modularize infrastructure as code, making deployments safer and easier to maintain.
Progress0 / 4 steps
1
Create the main CloudFormation template skeleton
Create a CloudFormation template called main_template.yaml with an empty Resources section.
AWS
Need a hint?

Start with the basic CloudFormation template structure including AWSTemplateFormatVersion and Resources.

2
Add the NetworkStack nested stack resource
In main_template.yaml, add a resource called NetworkStack of type AWS::CloudFormation::Stack with a TemplateURL set to https://s3.amazonaws.com/mybucket/network.yaml.
AWS
Need a hint?

Use the AWS::CloudFormation::Stack resource type and set the TemplateURL to the network stack template location.

3
Add the ComputeStack nested stack with parameter passing
In main_template.yaml, add a resource called ComputeStack of type AWS::CloudFormation::Stack. Set its TemplateURL to https://s3.amazonaws.com/mybucket/compute.yaml and pass the VpcId parameter from the output of NetworkStack using Fn::GetAtt with attribute Outputs.VpcId.
AWS
Need a hint?

Use Parameters to pass VpcId from NetworkStack outputs using !GetAtt NetworkStack.Outputs.VpcId.

4
Complete the main template with description and resources
Ensure the main_template.yaml includes the AWSTemplateFormatVersion, a Description, and both nested stack resources NetworkStack and ComputeStack with their properties as specified.
AWS
Need a hint?

Review the entire template to ensure all required parts are included and correctly formatted.