AWS Classroom Series – 13/Jul/2021

CloudFormation contd..

  • Understand Cloudformation template structure

  • 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 Preview
  • Necessary software setup:

  • Developer Setup

    • Ensure visual studio code is installed
    • Cloudformation extension is installed
      Preview
  • 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

Preview

  • 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 Preview
    • No Interruption: This property can be updated without deletion so it is considered as no interruption Preview
    • Properties can be of primitive types or custom types (objects) Preview

Example 1: Lets create a vpc with cidr range of 192.168.0.0/16

  • Manual Steps Preview Preview Preview
  • 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 Preview
  • Refer Here for the samples created in the class.

Leave a Reply

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

About learningthoughtsadmin