What is AWS Cloudformation ?

Just like terraform AWS cloudformation is a AWS service that allows you to quickly setup AWS services using its template where you define all the resources that you need to launch.

AWS cloudformation, takes care of provisioning and configuring all the resources for us. With a single template you can easily manage multiple resources in one go. You can also use in different regions.

The another best advantage of Cloudformation stack is you can roll back the changes in no time. You can track the difference between two versions of stacks easily as they are text files.

Some of the other benefits of AWS Cloudformation are:

  • It is declarative way of managing your AWS Infrastructure.
  • Changes to the infrastructure are reviewed through the code.
  • Supports almost all AWS resources.
  • You need to create a template which is JSON or YAML file that contains information about the AWS resources that you want to include.
  • You can use template from AWS S3 URL or Upload a template file.

Table of content

AWS Cloudformation Components
AWS Cloudformation template
AWS Cloudformation Stacks
AWS Cloudformation Change sets
How does CloudFormation Works?
Conclusion

AWS Cloudformation Components

There are mainly three components in AWS cloudformation i.e. templates, stacks and change sets.

AWS cloudformation template

Every stack in cloudformation is based on template. A template is a JSON or YAML text file that defines all the resources we need to provision in AWS cloud. You may select three options to prepare template.

  • Template is ready
  • Use a sample Template
  • Create template in Designer.

For example if we need to create an AWS EC2 instance below is the template. You may either upload this template directly or upload in AWS S3 and use S3 URL.

AWSTemplateFormatVersion: 2010-09-09
Description: AWS EC2 instance template
Resources:
  MyEC2Instance:
    Type: 'AWS::EC2::Instance'
    Properties:
      ImageId: ami-0ff8a91507f77f867
      InstanceType: t2.micro
      KeyName: testkey
      BlockDeviceMappings:
        - DeviceName: /dev/sdm
          Ebs:
            VolumeType: io1
            Iops: 200
            DeleteOnTermination: false
            VolumeSize: 20

AWS Cloudformation Stacks

Whenever you create a stack, you also specify a template that CloudFormation uses to create whatever you described in the template.

AWS Cloudformation Change sets

To update the stack you will need to use change sets.

How does CloudFormation Works?

For creating a cloudformation stack Cloudformation stack makes calls to AWS to provision and configure resources. In order to work with Cloudformation, it should have necessary permissions to provision and deploy the resources.

The following steps are performed for resources to be provisioned with cloudformation:

  • Create cloudformation stack in YAML or JSON format. You can also use AWS CloudFormation Designer to create stacks easily.
  • Save the stack in AWS S3 bucket. Note, if you store the cloudformation stack locally not in AWS S3 , then cloudformation creates a bucket for each region in which you upload a template file. 
  • Create a CloudFormation stack by specifying the location of your template file (Amazon S3 URL). 
  • If you wish you can delete a stack at any point in time, the only thing you need to do is specify the stack to delete, and CloudFormation deletes the stack and all the resources in that stack. 

Conclusion

In this article you learnt AWS cloudformation is a AWS service that allows you to quickly setup AWS services using its template where you define all the resources that you need to launch

Leave a comment