• It is a AWS service
  • It simplifies Infrastructure Management
  • Used to model and set up AWS resources
  • Involves creating  template which lists AWS resources needed
  • responsible for provisioning and configuring AWS resources
  • Used by Elastic Beanstalk
  • Cloud formation (CFN) template describes all needed resources and their properties.
  • Template
    • has JSON format
    • JSON document gives instructions for CFN
    • Instructions on resources to act and what resources to create/update
  • Stack 
    • refers to CFN unit of grouping infra
  • Stack Policy
    • IAM style policy
    • governs what or who can change
    • can be added via CLI or UI
    • updated but cannot be removed
  • Create CFN template -> Add template to CFN -> Create CFNStack -> Resources (200 per template) -> Update template/Stack -> Delete Stack
  • Template components
    • Parameters  – used to pass variables into template
    • Mappings (allow processing of hash’s by CFN template)
    • Resources,
    • Outputs (results from template);
    •  Only Resources is mandatory.
    • CFN can run scripts within instances, expand files within instances, stack id(unique).
  • Use cases:
    • Template for manual deployment of bespoke infra.
    • create repeatable patterned environment (ex:wordpress site with DB)
    • run automated testing for CI/CD environments (dev, test, prod)
    • define an environment once, deployed
    • manage infra config using software development style versioning and testing concepts.
  • It provisions
    • Auto Scaling group
    • load balancer
    • and database
  • Can easily edit or delete resources  
  • manage a collection of resources as a single unit or stack.
  • Quickly replicate infrastructure
  • control and track changes to infrastructure

CloudFormation Working

  • Easily create an infrastructure stack, with CloudFormation by
    • making underlying service calls to AWS
    • provision and configure AWS resources.
  • calls are as per defined template.
  • CloudFormation perform only actions having permission to do.
  • CloudFormation template can be a JSON or YAML-formatted document
  • After all resources have been created, AWS CloudFormation reports stack creation
  • If stack creation fails, CloudFormation rolls back changes by deleting the resources that it created.

Steps

  • Design an CloudFormation template in AWS CloudFormation Designer or text editor.
  • Save template either in s3 or locally
  • Create an AWS CloudFormation stack by specifying the location of template file

Change Sets

  • It is a summary of proposed changes to stack
  • Used for stack updation
  • stack updation is done to reflect changes on resources being used
  • Before making changes, generate a change set
  • Change sets enables seeing impact of change on running resources, before implementing them.
  • Updates can cause interruptions, depending on resource and properties being updated
  • Change sets do not indicate successful stack update.
  • Example, changing Amazon RDS database instance name,
    • CloudFormation will create a new database and delete the old one and and will lose data in old database
    • With change set, see changes on database to be replaced, and plan accordingly

Updating a Stack with Change Sets

  • To update stack’s resources, modify stack’s template.
  • Do not create new stack and delete old one.
  • Instead, create change set by submitting a modified version of original stack template,
  • CloudFormation compares the modified with original template and generates a change set.
  • Change set lists the proposed changes.
  • After reviewing changes, execute the change set to update stack

Steps

  • Modify CloudFormation stack template using CloudFormation Designer or a text editor.
  • Save CFN template can be saved either to s3 bucket or locally
  • changeset is created to reflect any changes needed in stack
  • View changeset to check CloudFormation will perform with the changes
  • Execute changeset to apply to stack.

Enrich and Enhance your skills to become an AWS Certified Developer – Associate with hundreds of Free Practice Test. Try Now!

Menu