AWS Classroomnotes 20/Oct/2022

JSON and YAML

  • They are data representational formats
  • Both JSON and YAML use key value pairs to represent data
  • Both JSON and YAML have 3 types of data which we can represent
    • Simple/Scalar:
      • Text
      • Number
      • Boolean
    • Plural/List
    • Object/dictionary
  • JSON
  • YAML

Developing Cloud formation Templates

  • When developing Cloudformation template we can use json or yaml.
  • The structure of the template is defined by AWS Refer Here
  • JSON structure Refer Here
{
  "AWSTemplateFormatVersion" : "version date",

  "Description" : "JSON string",

  "Metadata" : {
    template metadata
  },

  "Parameters" : {
    set of parameters
  },

  "Rules" : {
    set of rules
  },

  "Mappings" : {
    set of mappings
  },

  "Conditions" : {
    set of conditions
  },

  "Transform" : {
    set of transforms
  },

  "Resources" : {
    set of resources
  },

  "Outputs" : {
    set of outputs
  }
}
---
AWSTemplateFormatVersion: "version date"

Description:
  String

Metadata:
  template metadata

Parameters:
  set of parameters

Rules:
  set of rules

Mappings:
  set of mappings

Conditions:
  set of conditions

Transform:
  set of transforms

Resources:
  set of resources

Outputs:
  set of outputs

  • Refer Here for template sections
  • Minimal Template in JSON
{
    "Resources": {}
}
  • Minimal Template in YAML
---
Resources:
  • Each resource can be defined in the resource section by the following syntax Refer Here

Activity-1: Hello Cloudformation in JSON

  • Ensure Visual studio code is installed.
  • Create a new folder and open this with vs code
  • Install cloudformation extension into visual studio code
    Preview
  • Create a new file template.json
  • Now since we want to create vpc google aws vpc cloudformation and open the section as shown below
    Preview
  • Refer Here for the syntax
  • Navigate to each property and verify the highlighted sections
    Preview
  • The template which we developed is
{
    "Resources": {
        "myvpc": {
            "Type": "AWS::EC2::VPC",
            "Properties": {
                "CidrBlock": "192.168.0.0/16",
                "Tags": [
                    {
                        "Key": "Name",
                        "Value": "activity1-vpc"
                    }
                ]
            }
        }
    }
}
  • Now we have template, when we execute template what we create is referred as stack in cloudformation.
    Preview
    Preview
  • Continue till create stack
    Preview
    Preview
    Preview
    Preview
  • Refer Here for the changes
  • To cleanup delete the stack
  • The same template in YAML is as shown below
---
Resources:
  myvpc:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 192.168.0.0/16
      Tags:
        - Key: Name
          Value: activity1-vpc

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner