BrainyBeeBrainyBee
ExploreBlogStart Studying
HomeAWS Certified DevOps Engineer - Professional (DOP-C02)Mastering Reusable Infrastructure: AWS CloudFormation Nested Stacks
Hands-On Lab782 words

Mastering Reusable Infrastructure: AWS CloudFormation Nested Stacks

Define cloud infrastructure and reusable components to provision and manage systems throughout their lifecycle

Mastering Reusable Infrastructure: AWS CloudFormation Nested Stacks

In this lab, you will learn how to implement Task Statement 2.1 of the AWS DevOps Engineer Professional exam: defining cloud infrastructure using reusable components. You will build a parent-child stack architecture that allows for modular infrastructure management.

[!WARNING] This lab involves provisioning real AWS resources. Remember to run the teardown commands at the end to avoid ongoing charges.

Prerequisites

  • An active AWS Account.
  • AWS CLI installed and configured with appropriate credentials.
  • IAM Permissions: AdministratorAccess (or permissions for CloudFormation, S3, and IAM).
  • A text editor (VS Code, Vim, or similar).

Learning Objectives

  • Create modular, reusable CloudFormation templates.
  • Implement a Root Template using the AWS::CloudFormation::Stack resource.
  • Manage infrastructure lifecycles through nested stack updates.
  • Apply standardized tagging and security configurations across reusable components.

Architecture Overview

Loading Diagram...
Figure 1 — Mermaid diagram

Conceptual Model of Reusability

Compiling TikZ diagram…
⏳
Running TeX engine…
This may take a few seconds
Figure 2 — TikZ diagram

Step-by-Step Instructions

Step 1: Create the Reusable S3 Component

First, we create a "Child" template that defines a standardized, encrypted S3 bucket. This template can be reused across different projects.

  1. Create a file named s3-component.yaml:
yaml
AWSTemplateFormatVersion: '2010-09-09' Parameters: BucketName: Type: String Resources: SecureBucket: Type: AWS::S3::Bucket Properties: BucketName: !Ref BucketName BucketEncryption: ServerSideEncryptionConfiguration: - ServerSideEncryptionByDefault: SSEAlgorithm: AES256 Outputs: BucketArn: Value: !GetAtt SecureBucket.Arn

Step 2: Upload Component to S3

CloudFormation nested stacks require the child templates to be stored in an S3 bucket that the service can access during deployment.

bash
# Replace <YOUR_LAB_ASSETS_BUCKET> with a unique name aws s3 mb s3://brainybee-lab-assets-<YOUR_ACCOUNT_ID> aws s3 cp s3-component.yaml s3://brainybee-lab-assets-<YOUR_ACCOUNT_ID>/templates/s3-component.yaml

Step 3: Create the Root Template

The root template "calls" the child template as a resource.

  1. Create a file named main-stack.yaml:
yaml
AWSTemplateFormatVersion: '2010-09-09' Resources: StorageLayer: Type: AWS::CloudFormation::Stack Properties: TemplateURL: https://brainybee-lab-assets-<YOUR_ACCOUNT_ID>.s3.amazonaws.com/templates/s3-component.yaml Parameters: BucketName: !Sub "reusable-infra-bucket-${AWS::AccountId}"

Step 4: Deploy the Infrastructure

Deploy the root stack using the AWS CLI.

bash
aws cloudformation create-stack \ --stack-name nested-infra-lab \ --template-body file://main-stack.yaml \ --capabilities CAPABILITY_IAM
▶Console alternative
  1. Navigate to
CloudFormation
Create stack

(With new resources). 2. Upload the

main-stack.yaml

file. 3. Follow the wizard, acknowledging IAM capabilities at the end.

Checkpoints

Verification TaskCommand / ActionExpected Result
Check Stack Statusaws cloudformation describe-stacks --stack-name nested-infra-labStackStatus is CREATE_COMPLETE
Verify Nested StackCheck the CloudFormation consoleTwo stacks exist: nested-infra-lab and a child stack starting with nested-infra-lab-StorageLayer
Verify EncryptionCheck S3 Bucket properties"Server-side encryption" is enabled (AES-256)

Troubleshooting

ErrorLikely CauseSolution
S3 Error: Access DeniedThe CloudFormation service role doesn't have access to your assets bucket.Ensure the S3 bucket permits s3:GetObject or use a public-read ACL (not recommended for production).
TemplateURL must point to a template located in an S3 bucketYou provided a local file path in the TemplateURL field.Ensure the URL starts with https://...s3.amazonaws.com/...
Circular DependencyA resource is waiting for an output that depends on itself.Use !DependsOn explicitly if needed, but check logic first.

Challenge

Objective: Modify the s3-component.yaml to include a LifecycleConfiguration that transitions objects to S3 Intelligent-Tiering after 30 days. Re-upload the file to S3 and update the root stack using the aws cloudformation update-stack command.

Cost Estimate

  • S3 Storage: Free Tier (if under 5GB). Minimal cost (~$0.023/GB) otherwise.
  • CloudFormation: No additional cost for AWS resources managed by CloudFormation.
  • Data Transfer: Negligible for this lab.
  • Total Estimated Spend: < $0.05 USD.

Concept Review

FeatureNested StacksCloudFormation Modules
Primary UseCreating groups of resources that are managed together.Encapsulating resource definitions into a single resource type.
VisibilityShows up as multiple stacks in the console.Shows up as a single stack; module is abstracted.
UpdatesUpdating child template requires updating the root stack.Managed via the CloudFormation Registry.

Teardown

To avoid ongoing costs, delete the stacks and the assets bucket created during this lab.

bash
# Delete the stacks aws cloudformation delete-stack --stack-name nested-infra-lab # Empty and delete the assets bucket aws s3 rm s3://brainybee-lab-assets-<YOUR_ACCOUNT_ID> --recursive aws s3 rb s3://brainybee-lab-assets-<YOUR_ACCOUNT_ID>
All AWS Certified DevOps Engineer - Professional (DOP-C02) Study Resources

Related Notes

  • Cloud Infrastructure & Reusable IaC Components940 words
  • Mastering AWS Alerting and Automated Remediation1,050 words
  • Study Guide: Analyzing Failed Deployments in AWS940 words
  • Incident Analysis: Troubleshooting Failed Processes in AWS1,050 words
  • Mastering AWS Monitoring & Security Analytics: Logs, Metrics, and Findings1,050 words
  • AWS Log Analysis: Athena, CloudWatch Insights, and OpenSearch920 words
  • Analyzing Real-Time Log Streams with Amazon Kinesis Data Streams985 words
  • CloudWatch Anomaly Detection Alarms: Professional Study Guide820 words
  • AWS Application Storage Patterns: EBS, EFS, and S31,054 words
  • Lab: Automating Security Controls and Data Protection with AWS Secrets Manager and Config942 words
  • Master Study Guide: Automating Security Controls & Data Protection (AWS DOP-C02)1,184 words
  • Mastering AWS CloudFormation StackSets: Multi-Account & Multi-Region Orchestration895 words

Ready to study AWS Certified DevOps Engineer - Professional (DOP-C02)?

Practice tests, flashcards, and all study notes — free, no sign-up.

Start Studying

Ready to study AWS Certified DevOps Engineer - Professional (DOP-C02)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free
AWS Certified DevOps Engineer - Professional (DOP-C02) ResourcesExplore All HivesBlogHome

© 2026 BrainyBee. Free AI-powered exam prep.

Loading Diagram...
Flowchart, top to bottom. Root Template: main.yaml connects to Nested Stack: VPC. Root Template: main.yaml"] --> B["Nested Stack: VPC connects to Nested Stack: S3 Storage. C connects to S3 Bucket (Encrypted). B connects to Public Subnet.