AWS CF Classroom Series – 25/Sep/2019

CloudFormation Template

  • JSON File

Lab Setup

  • Install Visual Studio Code

How to Write a CF Template

  • Create a directory "hellocf"
  • In this directory create a file "main.json"
  • Contents of main.json are
{
    
}
  • CF Template has a certain structure to be followed. Refer here for structure
  • Lets fill the basic elements in out template
{
  "AWSTemplateFormatVersion": "",
  "Description": "",
  "Resources": {
      
  }   
}
  • Lets Fill the AWSTemplateFormatVersion by referring here
{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "",
  "Resources": {

  }   
}
  • Lets Fill the Description with some purpose
{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "This is my first cf template",
  "Resources": {

  }   
}
  • Lets Write a Resource to create a network (VPC) in AWS
  • Google by using following query aws cloudformation <servicename>
  • Now create Resource in Resources section using following syntax
<ResourceName>: {
    "Type": "<Resource Type Defined by AWS>",
    "Properties" : {

    }
}
  • Now lets add the myvpc resource with 192.168.0.0/16 as the cidr range
{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "This is my first cf template",
  "Resources": {
      "myvpc":{
        "Type" : "AWS::EC2::VPC",
        "Properties" : {
            "CidrBlock" : "192.168.0.0/16",
            "Tags" : [ 
                {
                    "Key": "Name",
                    "Value": "From CF"
                }
            ]
          }
      }
      

  }   
}
  • So far we have written a Template
  • Now when we execute this template it becomes Stack
  • Stack Creates everything written in Template or nothing
  • To Create a stack login into AWS, Navigate to CloudFormation and then create a stack by uploading template.
  • Once you are done delete stack.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner