AWS Day 11: Journey into AWS CloudFormation

AWS Day 11: Journey into AWS CloudFormation

Infrastructure as Code (IaC) Made Easy

Sep 25, 2023ยท

5 min read

Play this article

Welcome to Day 11 of your AWS adventure! Today, we're plunging into the world of AWS CloudFormation (CFT), a powerful service that enables you to create and manage AWS resources using templates. In this blog post, we'll explore what CloudFormation is, its use of Infrastructure as Code (IaC) principles, the differences between CLI and CFT, key components, and features, and provide a practical demo. We'll also compare CloudFormation with Terraform and introduce AWS CloudFormation documents.

๐Ÿ”ถ What is CloudFormation?

AWS CloudFormation is a service that allows you to provision and manage AWS infrastructure resources in a systematic, automated, and repeatable manner. It uses templates, written in JSON or YAML, to describe the AWS resources and their configurations.

๐Ÿ”ถ How It Uses Principles of Infrastructure as Code (IaC)

CloudFormation adheres to the principles of Infrastructure as Code (IaC), treating infrastructure provisioning and management as software development. Benefits include version control, code review, and automation, ensuring that your infrastructure is consistent, predictable, and easily reproducible.

๐Ÿ”ถ Differences Between CLI and CloudFormation

  • CLI (Command Line Interface): Typically used for one-off tasks and manual interactions with AWS resources.

  • CloudFormation: Designed for provisioning and managing resources in a declarative manner, allowing infrastructure to be codified and version-controlled.

๐Ÿ”ถ Components of CloudFormation

  • Templates: JSON or YAML files that define AWS resources and their configurations.

  • Stacks: Sets of AWS resources created and managed together, forming a single unit.

  • Resources: AWS infrastructure components, such as EC2 instances, S3 buckets, and RDS databases.

  • Parameters: Values that you can input when creating or updating a stack to customize resource configurations.

  • Mappings: Key-value pairs used for mapping input parameters to specific values based on a provided key.

  • Outputs: Information about resources that can be displayed after stack creation.

๐Ÿ”ถ Features of CloudFormation

  • Rollback: Automatic rollback in case of stack creation or update failure.

  • Change Sets: Preview and execute changes before applying them.

  • Resource Drift Detection: Detects and displays differences between the expected and actual stack resources.

  • Cross-Stack References: Share resources between stacks.

๐Ÿ”ถ Comparison with Terraform

Terraform is another popular IaC tool. While both Terraform and CloudFormation offer similar capabilities, Terraform is cloud-agnostic and supports multiple cloud providers, whereas CloudFormation is AWS-specific.

๐Ÿ”ถ AWS CloudFormation Documents

AWS CloudFormation provides a wealth of documentation, including templates and examples, on its official documentation page.

๐Ÿ”ถ Assignment: Create an EC2 Instance Using AWS CloudFormation

For your assignment, create a CloudFormation template that provisions an EC2 instance. Define parameters for customization and outputs for resource information. Execute the template using the AWS CloudFormation service.

Creating an EC2 instance using AWS CloudFormation (CFT) involves creating a CloudFormation template that describes the resources you want to provision. Below is a step-by-step guide to creating an EC2 instance using CloudFormation:

Step 1: Create a CloudFormation Template

You'll need to create a CloudFormation template in JSON or YAML format. Here's a simple YAML example to create an EC2 instance:

AWSTemplateFormatVersion: '2010-09-09'
Description: 'EC2 Instance Creation'

    Type: AWS::EC2::Instance
      InstanceType: t2.micro
      ImageId: ami-053b0d53c279acc90 # Replace with your desired AMI ID
      KeyName: CP-keys       # Replace with your EC2 key pair name

Save this template to a file, e.g., ec2-instance-template.yml.

Step 2: Deploy the Stack

CloudFormation dashboard: click the "Create stack" button to start the stack creation process.

Select Template: In the "Create stack" wizard, you'll be prompted to choose a template. There are two options:

  • The template is ready: If your template is already available on Amazon S3 or in your local file system, choose this option.

  • The template is in Amazon S3: If your template is hosted on Amazon S3, you can provide the S3 URL.

For this example, let's assume you're using a template file on your local system. Choose "Template is ready" and click "Upload a template file." Then, click the "Choose file" button and select your CloudFormation template file (e.g., ec2-instance-template.yml) from your local system.

Step 3: Monitor Stack Creation

Wait until the stack status becomes CREATE_COMPLETE.

Step 4: Access Your EC2 Instance

Check AWS EC2 whether your instances running.

Now we have successfully created and connected to an EC2 instance using AWS CloudFormation. Make sure to replace placeholders like ami-XXXXXXXXXXXXXXXXX, YourKeyPairName, and your-stack-name with your specific values.

In conclusion, AWS CloudFormation is a powerful service for managing AWS infrastructure as code. By codifying your infrastructure, you can enhance its consistency, scalability, and maintainability. As you progress in your AWS journey, CloudFormation proficiency will become a valuable skill for streamlining resource provisioning and management.

Stay tuned for more AWS insights, hands-on guides, and best practices as you navigate the cloud with AWS CloudFormation.

Happy templating and CloudFormation mastery!

๐Ÿ”ถ Learning Resources:

Throughout my AWS journey, I've found valuable learning materials to enhance my understanding. One such resource that has been incredibly helpful is the YouTube playlist titled 'AWS Zero to Hero'

As I continue sharing my AWS experiences in this blog series, I encourage you to explore this playlist and stay curious about the ever-evolving world of AWS.

#AWS_Zero_to_Hero Repo:

Happy Learning!

Stay in the loop with my latest insights and articles on cloud โ˜๏ธ and DevOps โ™พ๏ธ by following me on Hashnode, LinkedIn (, and GitHub (

Thank you for reading! Your support means the world to me. Let's keep learning, growing, and making a positive impact in the tech world together.

#Git #Linux Devops #Devopscommunity #90daysofdevopschallenge #python #docker #Jenkins #Kubernetes #Terraform #AWS

Did you find this article valuable?

Support CHANDRESH PATLE by becoming a sponsor. Any amount is appreciated!