top of page
Writer's picturePradeep P

Introduction to CloudFormation

Introduction

When we are learning AWS, we usually make use of the AWS Console to create all the required resources. We connect them together and get them to work as expected. This works when we have just 1-2 instances of these resources required. For any production grade application, this will not be a feasible solution for at least the following reasons:

  1. There will be a huge number of resources that will be usually required

  2. Creating resources and configuring them from the console is a manual process and thus error prone

  3. Recreating the same resource stack on a different region or post some accidental deletes will again take a long time

Thus, instead of having a manual process to perform these actions, it is better to make use of the concept of Infrastructure as Code (IaC). IaC essentially means that, the entire process of creating the required infrastructure shall be defined by a piece of code. The code will get executed when required and the cloud provider shall accordingly provision the required resources, configure them as per the code and also connect them as such.

AWS CloudFormation is AWS’s take on the IaC. Using CloudFormation, we can define the resources we want to deploy and AWS shall take care of creating and configuring the same.

CloudFormation is a declarative way of specifying the resources we want created. CloudFormation takes care of then creating these resources in the appropriate order as well.

Some advantages of using CloudFormation are:

  1. Making use of IaC concepts

  2. The infrastructure need is declared in code. Thus, the code can be reviewed, versioned and checked in to a repository as well

  3. The estimated cost of the resources that will be deployed can also be determined

  4. We can automate the deletion and creation of the stacks to save costs (for e.g., delete the dev resources on a weekend and recreate them Monday morning)

  5. Declarative approach (so that we don’t have to worry about the sequence of the resource creation)

  6. Easier to track all the resources that are to be created for a specific purpose, under a single stack. When no longer needed, the stack can be deleted and this deletes all the resources under the stack

Terminology

Template

A CloudFormation Template represents the declarative code which shall later be translated into actual infrastructure creation

Stack

A CloudFormation Stack is a collection of AWS resources that can be managed as a single unit. The stack shall consist of all the AWS resources that have been requested by the CloudFormation Template

When a stack is deleted, all the resources created as part of it shall be deleted

Change Sets

We might want to update an existing stack. Before updating the stack, we can generate a Change Set based on the updated template. This provides us the information about the changes that will occur in the running stack

Resources

Resources in the CloudFormation templates specify the resources that we are requesting for creation. This usually means resources like EC2, Elastic IP, Security Groups, etc.

Parameters

Dynamic inputs for the templates

Mappings

Static variables for the templates

Outputs

References to resources that have been created (for other templates to use)

Conditionals

Conditions to specify the resource creation

Metadata

Metadata for the template (to provide info on what the template does and represents)

Deploying CloudFormation Templates

There are multiple ways to deploy CloudFormation templates:

  1. CloudFormation templates can be declared as YAML / JSON files. These are then uploaded to S3 and the deployment can be started based on this YAML / JSON file

  2. The YAML / JSON files can be imported in the CloudFormation page in the AWS Console directly (these still get saved to S3)

  3. We can use the AWS CLI / SDK to deploy these templates.

  4. Additionally, we can also create the templates from within the AWS Console as well.

I will talk in detail about how to create, update and edit CloudFormation stacks in a further blog. 😊

References

4 views

Recent Posts

See All

Comments


bottom of page