Amazon AWS

What is AWS CloudFormation?

Welcome, in this tutorial, we will explain the theoretical background of the AWS Cloudformation and its related terminology.

1. Introduction to AWS Cloudformation

Amazon Cloudformation is a service responsible to create AWS resources and provision them in a well-ordered fashion.

cloudformation
  • It is known as infrastructure as a code
  • It is different from Elastic Beanstalk as the latter is focused on deploying applications on elastic compute
  • It uses JSON or YAML template files
  • Similar to Terraform
  • It consists of:
    • Stacks – Tells the entire environment described by the template and created, updated, and deleted as of a single unit
    • Changesets – Tells the summary of proposed changes to the stack which allows seeing how the changes will impact the existing resources before implementing them
  • Integrates with other development and CI/CD tools

1.1 Anatomy of a Template

A cloudformation template file consists of three main sections i.e. Parameters, Resources, and Outputs.

  • The parameter is responsible to define the user-defined values in the template. Using parameters makes the template reusable. When a user creates a new stack for the template, the cloudformation interface will provide fields for them to fill out the parameter values
  • The resource is the main recipe of the template. It defines which AWS resources should be created when this template is run through cloudformation
  • The output is where we define the information that should be provided to the user after the resources are created

1.2 Pricing

  • Cloudformation is free of cost for the users
  • Users only pay for the provisioned AWS resources created using the cloudformation template

1.3 Updating Stacks

  • AWS cloudformation provides 2 methods for updating the stacks – direct update or creating and executing the changesets
  • In a direct update, the user submits changes and cloudformation deploys them immediately. Offers to quickly deploy the updates
  • In changesets, the user can preview the changes cloudformation will make to the stack and then decide whether to apply the new changes or not

1.4 Sample Cloudformation template

The below cloud formation template helps to set up the basic layout for writing the cloudformation template. The following code will provide us with a base for building our template.

Cloudformation Template

AWSTemplateFormatVersion: '2010-09-09'
Description: 'Explain what this template does'
Parameters:
  # User-defined values that will be used when creating AWS resources
Resources:
  # Specify AWS Resources to be created
Outputs:
  # Important information that should be provided to the user after the resources have been created

2. Best practices

  • Planning and organizing
    • Organize the stacks by ownership
    • Reusing the template to replicate stacks in multiple environments
    • Using nested stacks to reuse the common template patterns
  • Creating templates
    • Using AWS specific parameters
    • Using parameters
    • Validating templates before executing them
    • Do not hardcode credentials in templates
  • Managing stacks
    • Managing stack through cloudformation
    • Creating changesets before updating the stacks
    • Using Stack policies
    • Using AWS Cloudtrail for auditing purposes
    • Using version control to manage the cloudformation templates

That is all for this tutorial and I hope the article served you whatever you were looking for. Happy Learning and do not forget to share!

3. Summary

In this article:

  • We did an introduction to Amazon Cloudformation and its concepts
  • We used a code snippet to understand the template
  • We described its best practises to use

You can find more AWS articles here.

Yatin

An experience full-stack engineer well versed with Core Java, Spring/Springboot, MVC, Security, AOP, Frontend (Angular & React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).
Subscribe
Notify of
guest

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

0 Comments
Inline Feedbacks
View all comments
Back to top button