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

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

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

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube