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:
- 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": {}
}
---
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

- Create a new file template.json
- Now since we want to create vpc google
aws vpc cloudformation and open the section as shown below

- Refer Here for the syntax
- Navigate to each property and verify the highlighted sections

- 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.


- Continue till create stack




- 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
Like this:
Like Loading...