AWS Classroom Notes – Cloudformation – 25/Dec/2019

Cloud Formation Template

  • CF Template gives easier way to create aws application/infrastructure creational/update templates.

  • It allows us to define parameters

  • Template can be shared with others to create the application/infra in any account.

  • CF Templates can be called from CI/CD Engines like jenkins

  • CF Template can be written for any service to create any resource.

  • CF Templates can be written in

    • JSON
    • YAML
  • Example Scenario: Create the following in AWS Preview

  • Evaluate the Scenario:

    • Console: Creation is simple but repetition can be difficult
    • CLI: Scripting might require some prior knowledge, but changes will be difficult to handle in repetition
    • CF Template: Create is time consuming but repetition is effective and easy.

Cloud Formation Basics

  • Template: JSON/YAML file which has resources, parameters etc
  • Resource: Any thing which can be created in AWS
  • Parameter: Input from user
  • Output: result of execution of Template
  • Stack: Stack is required for execution of Template.

Cloud Formation Syntax

{
  "AWSTemplateFormatVersion" : "version date",

  "Description" : "JSON string",

  "Metadata" : {
    template metadata
  },

  "Parameters" : {
    set of parameters
  },

  "Mappings" : {
    set of mappings
  },

  "Conditions" : {
    set of conditions
  },

  "Transform" : {
    set of transforms
  },

  "Resources" : {
    set of resources
  },

  "Outputs" : {
    set of outputs
  }
}
  • Sample Minimal Template
{
  "AWSTemplateFormatVersion" : "2010-09-09",
  "Description" : "learning cf",
  "Resources": {

  }
}

Sample AWS CF Template for Creating S3 bucket

  • Manually create a S3 bucket to understand the approach.
  • Create a directory and create a json file in this with following content
{
  "AWSTemplateFormatVersion" : "2010-09-09",
  "Description" : "learning cf",
  "Resources": {

  }
}
  • Now since we are supposed to create a s3 resource, google aws cloudformation s3 bucket Preview
  • Now click and open the aws docs which has the resource structure/syntax defined. Preview
  • The following content will be enough to create s3 bucket
{
    "AWSTemplateFormatVersion" : "2010-09-09",
    "Description" : "learning cf",
    "Resources": {
        "mys3": {
            "Type" : "AWS::S3::Bucket",
            "Properties": {
                "BucketName": "qt-s3-learning-forcf.com"
            }
        }
    }
}
  • Now navigate to CLoudformation Service and Create stack by uploading the above template.

Dev Environment Setup

  • From here Refer Setting up your machine for AWS CloudFormation section

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner