This lab walks you through the steps to create a Nested Stack using cloudFormation.
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.
Duration: 1 hour
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.
CloudFormation is a service provided by AWS for designing our own infrastructure using code i.e infrastructure as code.
Currently, CloudFormation supports two languages JSON and YAML. You can write your code with one of the languages.
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.
A fascinating feature of CloudFormation is that it saves more time in building infrastructure and helps in focusing on the development.
It is also possible to replicate our infrastructure in a short amount of time.
It eliminates human error and works according to the code you have written. It consists of two main components, Stack and Templates.
It consists of various sections like
AWS Template Format Version
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.
The resources section plays an important role in the template creation.
For example, to create an EC2 instance, a template shall consist of various parameters such as key name, image id, instance type.
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.
A stack consists of a collection of resources.
In other words, the stack consists of one or more templates.
The advantage of the stack is that it is easy to create, delete or update the collection of resources.
The advanced stacks have a nested stack which holds a collection of stacks.
As the name suggests, a Nested Stack consists of one or more stacks referencing each other.
As infrastructure scales, a particular CloudFormation template may need to be used multiple times.
In such cases, we isolate a common template and reference it as needed from a nested stack.
Nested stack itself consists of one or stacks in a reference hierarchy.
Nested Stack will have a parent stack that has one or more child stacks.
In this lab, we are going to see the example of a Nested Stack by creating an Autoscaling group stack and a Load balancer stack and attaching the Load Balancer stack to the Autoscaling stack.
Launching Lab Environment
Understand the CloudFormation Template
Template for Autoscaling group
Template for a Load Balancer
Template for a Nested Stack
Editing Nested_stack.yaml file
Creating a web server with an Autoscaling group and a Load balancer using a CloudFormation Nested stack
Check the resources created by the Nested Stack
Checking for an Auto Scaling group
Checking for Launch configuration
Checking for an EC2 instance
Checking for a Load Balancer
Testing the load balancer
Validation of the lab