Skip to content

MonseGuzman/cloudFormation-stacks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS CloudFormation - Nested Stacks

This repository contains a set of AWS CloudFormation templates designed to practice and demonstrate the implementation of Nested Stacks. The goal is to build a modular, reusable, and organized infrastructure by decoupling components into specialized templates.

🤗 Project Overview

Using Nested Stacks allows for better management of complex architectures. In this little project, a "Parent" (or "Root") stack is used to orchestrate the deployment of multiple "Child" stacks, passing parameters between them and centralizing the lifecycle of the entire infrastructure.

🧬 Current Architecture

The project follows a modular structure:

  • Root Stack: The main entry point that defines AWS::CloudFormation::Stack resources.
  • Child Stacks: Individual templates for specific resources (e.g., Networking, Security Groups, EC2 instances, or S3 Buckets).

📁 Repository Structure

.
├── components/              # Directory for child templates
│   └── cloudwatch.yaml      # WIP
│   ├── ec2.yaml             # Compute layer (EC2, SSH key, SG rules)
│   ├── loadbalancer.yaml    # Traffic layer (LB, WAF)
│   └── network.yaml         # Compute resources (EC2, ASG, etc.)
├── root-stack.yaml          # Main template to deploy all nested stacks
└── parameters/              # (Optional) Environment-specific configurations

🫨 Prerequisites

  • An AWS Account.
  • AWS CLI configured with 🫵🏼 appropriate permissions.
  • (Optional) An S3 Bucket to host the child templates (CloudFormation requires nested templates to be accessible via an S3 URL or file path during deployment).

🏃🏻‍♀️ How to Deploy

There are two options to deploy the resources:

  1. Create a S3 Bucket.
  2. Upload the child templates to S3 Bucket.
aws s3 cp components/ s3://your-bucket-name/cloudformation/components/ --recursive
  1. Update the TemplateURL parameter in the root-stack.yaml file.

Nested stacks require the TemplateURL to point to a valid location.

  1. Deploy the Root Stack:
aws cloudformation create-stack \
  --stack-name nestedPractice \
  --template-body file://root-stack.yaml \
  --parameters ParameterKey=BucketURL,ParameterValue=[https://your-bucket-name.s3.amazonaws.com/cloudformation/](https://your-bucket-name.s3.amazonaws.com/cloudformation/) \
  --capabilities CAPABILITY_IAM

OR

You can run the deploy.sh script and it will create a S3 Bucket and deploy/destroy the resources.

chmod +x ./deploy.sh
export AWS_REGION=<REGION>

./deploy.sh <RESOURCES_NAME>

About

A hands-on repository for AWS CloudFormation Nested Stacks. Exploring modular IaC, cross-stack parameter passing, and infrastructure orchestration

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages