JSON and YAML
- Both json and YAML are data definition formats
- JSON and YAML use name value pairs to describe data
- value are of two types
- JSON (JavaScript Object Notation)
- name value pair
- text
"name": "LT"
- number:
"age": 5
- bool:
"online": true
- list/array:
"courses": ["AWS", "Azure", "GCP" ]
- map/dictionary:
"address": { "flat": "601", "building": "nilgiri" }
-
YAML:
- name value pair
- text
name: LT
- number:
age: 5
- bool:
online: true
- list/array
“`yaml
courses: ["AWS", "Azure", "GCP" ]
courses:</li>
<li>AWS</li>
<li>Azure</li>
<li>GCP
“`
- object/map
yaml
address: { "flat": "601", "building": "nilgiri" }
address:
flat: 601
building: nilgiri
-
Json files will have .json as extension generally and yaml files will have extensions of .yml or .yaml
- Lets write a json file to describe a movie
{
"Title": "The Lord of the Rings",
"Director": "Peter Jackson",
"Budget": 281,
"Editors": ["John Gilbert", "Michael Horton", "Jamie Selkirk"],
"Characters": {
"Gandalf": "Gandalf the Grey is a wizard, the first leader of the Fellowship, and the possessor of one of the three Elf rings which can be controlled by the Ring of Power. Whether he's really been killed by the Balrog, a monster of fire, or not, like the Terminator and like Spock, Gandalf will come back.",
"Frodo": "Frodo is the Ring-Bearer. Inheriting the Ring of Power from his cousin Bilbo, Frodo learns from Gandalf that the ring is about to bring its evil to the gentle beauty of the Shire if it remains there. Frodo accepts the responsibility for destroying the ring in the fires of Mordor, the evil location from which it came. He's accompanied on this dangerous quest by the Fellowship of the Ring - Gandalf, Aragorn, Boromir, Legolas, Gimli, Sam, Merry and Pippin."
}
}
---
Title: The Lord of the Rings
Director: Peter Jackson
Budget: 281
Editors:
- John Gilbert
- Michael Horton
- Jamie Selkirk
Characters:
Gandalf: |
Gandalf the Grey is a wizard, the first leader of the Fellowship, and the possessor of one of the three Elf rings which can be controlled by the Ring of Power. Whether he's really been killed by the Balrog, a monster of fire, or not, like the Terminator and like Spock, Gandalf will come back. But this time, our white knight switches to a more appropriate costume as "Gandalf the White."
Frodo: |
Frodo is the Ring-Bearer. Inheriting the Ring of Power from his cousin Bilbo, Frodo learns from Gandalf that the ring is about to bring its evil to the gentle beauty of the Shire if it remains there. Frodo accepts the responsibility for destroying the ring in the fires of Mordor, the evil location from which it came. He's accompanied on this dangerous quest by the Fellowship of the Ring - Gandalf, Aragorn, Boromir, Legolas, Gimli, Sam, Merry and Pippin.
Infrastructure as Code
- Express the Infrastructure as a Desired State and Pass this to a tool which creates the infra
- Examples of tools:
- Terraform
- Cloudformation
- ARM Templates
- Azure Bicep
- Pulumi
- Cloudformation is an AWS specific IAC tool which accepts json/yaml as input
- ARM Template in an Azure specific IAC tool which accepts json
- Generally the input which you give to these tools are referred as templates.
Cloudformation
{
"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
}
}
- Out of all the sections above, Resources is the mandatory section, rest of all are optional
Activity 1: Create a vpc
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"ntier": {
"Type": "AWS::EC2::VPC",
"CidrBlock": "10.0.0.0/16",
"EnableDnsHostnames": true,
"Tags": [
{
"Key": "Name",
"Value": "ntier"
}
]
}
}
}
- To execute the tempalte we need to create a stack (cloud formation stack)
- Cloudformation creates resources for json/yaml templates passed. By default cloudformation creates everything or nothing (in cases of errors)
- Once we delete stack all resources will be deleted.
- Now lets create a cloudformation stack
- Now lets create parameters to accept inputs from users Refer Here
Like this:
Like Loading...