CloudFormation contd..
-
Understand Cloudformation template structure
- Refer Here for the official documentation
-
Lets try to create a cloudformation template to create an s3 bucket
- Resource: S3 bucket
- Information to be passed
- name of the bucket
- location of bucket
-
Necessary software setup:
- Refer Here for softwares
- Windows Terminal Refer Here
-
Developer Setup
- Ensure visual studio code is installed
- Cloudformation extension is installed
-
Refer Here for the json and yaml template to create the s3 bucket
-
Write Cloudformation template to create two s3 buckets
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "exploring cloud formation",
"Resources": {
"mys3bucket1" : {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "qts3cfjson1"
}
},
"mys3bucket2" : {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "qts3cfjson2"
}
}
}
}
- In yaml
AWSTemplateFormatVersion: '2010-09-09'
Description: exploring cloud formation
Resources:
mys3bucket1:
Type: AWS::S3::Bucket
Properties:
BucketName: qts3cfjson1
mys3bucket2:
Type: AWS::S3::Bucket
Properties:
BucketName: qts3cfjson2
- When we want to create resources using cloudformation we create a template in json or yaml file and then we create a stack in cloudformation and use the template.
- To create resources we need to provide type and properties.
- Once the cloudformation stack has created resources we can make changes as well by adding/modifying properties. Some property changes may lead to deletion and recreation of resources
- Replacement: Deletes and recreates the resource
- No Interruption: This property can be updated without deletion so it is considered as no interruption
- Properties can be of primitive types or custom types (objects)
- Replacement: Deletes and recreates the resource
Example 1: Lets create a vpc with cidr range of 192.168.0.0/16
- Manual Steps
- We are creating a resource vpc with cidr range of 192.168.0.0/16
- The template is as shown below
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "exploring cloud formation",
"Resources": {
"myvpc": {
"Description": "this is my vpc",
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "192.168.0.0/16",
"Tags": [
{
"Key": "Name",
"Value": "vpcfromcf"
},
{
"Key": "CreatedBy",
"Value": "CloudOps"
}
]
}
}
}
}
- Creation of stack will lead to a vpc resource
- Refer Here for the samples created in the class.
