Support Documents

AWS CloudFormation Nested Stacks

Lab Details

  1. This lab walks you through the steps to create a Nested Stack using cloudFormation.

  2. In this lab, you will create two separate stacks for Auto Scaling and Load Balancing and then attach the Autoscaling group to the Load balancer using a Nested Stack.

  3. Duration: 1 hour

  4. AWS Region: US East (N. Virginia) us-east-1


    Before going into Nested Stack, we need to be familiar with a few concepts such as Cloudformation, Stack and Template


  1. CloudFormation is a service provided by AWS for designing our own infrastructure using code i.e infrastructure as code.

  2. Currently, CloudFormation supports two languages JSON and YAML. You can write your code with one of the languages.

  3. CloudFormation comes with great features being able to update your infrastructure whenever you want and also having the ability to delete the stack in case you don’t need it.

  4. A fascinating feature of cloudFormation is that it saves more time in building infrastructure and helps in focusing on the development.

  5. It is also possible to replicate our infrastructure in a short amount of time.

  6. It eliminates human error and works according to the code you have written. It consists of two main components, Stack and Templates.


  1. Cloudformation

  2. It consists of various sections like 

  • AWS Template Format Version

  • Description

  • Metadata

  • Parameters

  • Mappings

  • Conditions

  • Resources

  • Outputs

  1. It is not mandatory that the template requires all the above-mentioned sections. By using only the Resources section, we will be able to create a template.    

  2. The resources section plays an important role in the template creation.

  3. For example, to create an EC2 instance, a template shall consist of various parameters such as key name, image id, instance type.

  4. It is also possible to create two resources in the same template and refer to one from another i.e. attaching an elastic IP with an EC2 instance.


  1. A stack consists of a collection of resources. 

  2. In other words, the stack consists of one or more templates.

  3. The advantage of the stack is that it is easy to create, delete or update the collection of resources.

  4. The advanced stacks have a nested stack which holds a collection of stacks.

Nested Stack

  1. As the name suggests, a Nested Stack consists of one or more stacks referencing each other.

  2. As infrastructure scales, a particular CloudFormation template may need to be used multiple times.

  3. In such cases, we isolate a common template and reference it as needed from a nested stack.

  4. Nested stack itself consists of one or stacks in a reference hierarchy.

  5. Nested Stack will have a parent stack that has one or more child stacks.


  1. Log into the AWS Management Console.

  2. Go through the Cloudformation template to understand all the terminologies.

  3. Create the nested stack using the YAML file provided in the S3 bucket.

  4. Finally, test the Environment created by CloudFormation Stack.

 Architecture Diagram