AWS Cloudformation Template: Benefits, Format Example

AWS Cloudformation Template: Benefits, Format Example

July 1, 2020 / Nirav Shah

Cloud formation is a service that allows you to manage, configure and provision your AWS infrastructure as code and all resources are defined using cloud formation template. This template interacts with API calls and creates resources that you define.

It supports YAML and JSON.

Benefits Of Cloudfromation Templates

  1. Less time as compared to when the configuration is done manually.
  2. Free to use (however you are charged for what you create and usage of AWS services).
  3. Can be used to manage updates & dependencies.
  4. Can be used to rollback and delete entire stack as well.

What is a cloud formation template

Now let’s see what is a cloud formation template.
YAML or JSON template used to describe the end state of the infrastructure you are either provisioning or changing.
You can upload the cloud formation template on s3 bucket.
Cloud formation reads the temples and makes the API call on your behalf.

Cloudformation template yaml example

The resulting resources are called a stack.

AWS Cloudformation Template format is shown in the following YAML template.

AWSTemplateFormatVersion: "2010-09-09"
Description: A sample template
Resources:
  MyEC2Instance: #An inline comment
    Type: "AWS::EC2::Instance"
    Properties: 
      ImageId: "ami-0ff8a91507f77f867" #Another comment -- This is a Linux AMI
      InstanceType: t2.micro
      KeyName: testkey
      BlockDeviceMappings:
        -
          DeviceName: /dev/sdm
          Ebs:
            VolumeType: io1
            Iops: 200
            DeleteOnTermination: false
            VolumeSize: 20

So from the above example, you can see that this template is about creating an EC2 instance and the size is t2 micro, and we have set the permission to delete on termination. And the keyname is testkey.

Cloudformation template JSON example

So it’s very easy to understand. Here we have defined the JSON format.

"Metadata": {
  "AWS::CloudFormation::Designer": {
    "6b56eaae-0bb6-4215-aad6-12345EXAMPLE": {
      "size": {
        "width": 60,
        "height": 60
      },
      "position": {
        "x": 340,
        "y": 430
      },
      "z": 2,
      "parent": "21ccc9b0-29e9-4a86-9cf2-12345EXAMPLE",
      "embeds": [],
      "ismemberof": [
        "c3eead73-6a76-4532-9268-12345EXAMPLE"
      ]
    },

Learn more about Cloudformation Template anatomy from AWS documentation

What is Template Snippets

It provides a number of example scenarios that you can use to understand how to declare various AWS CloudFormation template parts.

Like….

Please visit the links to get more information.

Also Read: AWS Elastic Beanstalk vs OpsWorks vs CloudFormation

Talk to AWS Certified Consultant

    Spread Love By Sharing:

    Let’s Talk About Your Needed AWS Infrastructure Management Services

    Have queries about your project idea or concept? Please drop in your project details to discuss with our AWS Global Cloud Infrastructure service specialists and consultants.

    • Swift Hiring and Onboarding
    • Experienced and Trained AWS Team
    • Quality Consulting and Programming
    Let’s Connect and Discuss Your Project