AWS Classroom Series – 03/Feb/2021

AWS Cloud Formation

  • This is a service that helps you model and setup AWS resources so that we spend less time managing the resources and focus on applications that run in AWS.
  • We describe our AWS resources in a template in a syntax specified by Cloudformation Grammar and Cloudformation takes care of provisioning and configuring the resources.
  • This helps in
    • recreating the infrastructure into various environments.
    • Easily controlling and tracking changes in your infrastructure.
  • Terminology
    • Template:
      • This is a JSON or YAML formatted text file which describes the resources which we want to create.
    • Stack:
      • To execute CF template we create a stack and in the stack all the resources created are managed.
    • Changeset:
      • To make changes in the executing resources of stack, we create changesets i.e. summary of proposed changes.
      • We update stacks using changesets.
  • How does CF Work
    • Create or use an existing template
    • Save the template locallay or in S3 bucket
    • Now AWS Cloudformation will create stack based on your template

JSON and YAML

  • These are the files which can store data in name value pairs.
  • Json and YAML Refer Here

AWS Cloudformation Template Grammar

  • Refer Here for the template structure
  • Json Structure
{
  "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
  }
}
  • In the above template structure the only required field is resources, which describes the resources which you want to create in AWS
{
    "Resources": {
        set of resources
    }
}
  • Lets Try to write a cloudformation template to create an s3 bucket
    • ManualSteps: Preview Preview Preview Preview Preview
  • Now lets see how to create a resource in Cf template. Refer Here
  • Now google for AWS cloudformation resource s3 Refer Here for the resource documentation Preview Preview
  • We have created a template which looks like
{
	"Resources": {
		"mys3bucket" : {
			"Type" : "AWS::S3::Bucket",
			"Properties" : {
				"BucketName": "qts3fromcftbd"
			}
		}
	}
}
  • Now lets create stack Preview Preview Preview Preview Preview Preview Preview
  • Now delete the stack to delete the resources created by cloudformation.
  • Refer Here for the changeset.

Leave a Reply

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

About learningthoughtsadmin