What is AWS CloudFormation?

  1. Home
  2. AWS
  3. What is AWS CloudFormation?
What is AWS CloudFormation?

AWS CloudFormation is a service that assists you in modeling and setting up your Amazon Web Services resources so you can spend less time managing them and more time working on your AWS-based applications. You construct a template that outlines all of the AWS resources you want (such as Amazon EC2 instances or Amazon RDS DB instances), and CloudFormation handles provisioning and configuration for you. You don’t have to create and configure AWS resources one by one, or figure out what’s reliant on what; CloudFormation does it for you. 

Overview of AWS CloudFormation

AWS CloudFormation is an Amazon service that assists customers in setting up and modeling AWS resources. It helps you to spend less time and energy managing AWS resources and more time and energy focusing on the apps that operate on AWS. It intends to take the best possible care of the AWS resources’ configuration and provisioning for the users.

There’s no need to manually create or configure these resources anymore because AWS CloudFormation takes care of everything. In this post, you’ll learn more about AWS CloudFormation, including how to use it and how effective it is. Let’s get started:

Why should one use CloudFormation?

  • You will need this AWS service for launching an instance.
  • You can easily create LoadBalancers.
  • It can be used for making required installations
  • It is used to attach instance to the LoadBalancers.
  • For creating RDS and configuring the EC2 security group, DBSecurity group, DBSubnet group, and DBParameter group. 
  • It is aslo usd for creating & configuring the security groups
  • Last but not least, it is used for creating auto-scaling group

Drawbacks of Using AWS CloudFormation

  • Incomplete Modelling
    • Despite the fact that the AWS service presentation website claims that AWS CloudFormation provides entire cloud infrastructure modelling, this is not the case.
  • Time Consuming
    • If it is true that once a template is packed, it is faster to execute than a manual template, the template production process is a lengthy trial and error process. It is impossible to check a template 100 percent locally; the only way to be sure of syntactic accuracy is to execute it first. That means you’ll have to make a lot of effort before you get a working version, each of which will take a long time to complete.
  • Unintelligible errors
    • Error messages are frequently pointless, deceptive, ineffective, or plain incorrect. Only one thing is certain: the stack has failed. What went wrong and why is as important to know as it is difficult to figure out.
  • Cloudformation drift detection
    • Many users requested AWS CloudFormation’s drift detection, which consists of the ability to automatically detect changes to the configuration of stack resources outside of CloudFormation via the AWS management console, the CLI, and the SDK.

Features of AWS CloudFormation

Templates

A CloudFormation template is a text file that is formatted in JSON or YAML. These files can be saved with any extension, including.json,.yaml,.template, and.txt. These templates serve as blueprints for creating AWS resources in CloudFormation. For example, you can include information about an Amazon EC2 instance in a template, such as an instance type, AMI ID, block device mappings, and the name of the Amazon EC2 key pair. You supply a template when you construct a stack, which CloudFormation utilizes to create anything you indicated in the template.

If you use the following template to generate a stack, CloudFormation will create an instance with the AMI ID ami-0ff8a91507f77f867, the t2.micro instance type, the testkey key pair name, and an Amazon EBS volume.

Stacks

You manage connected resources as a single unit called a stack when you use CloudFormation. By constructing, updating, and removing stacks, you can create, update, and destroy a collection of resources. The CloudFormation template for a stack defines all of the resources in the stack. Assume you have an Auto Scaling group, an Elastic Load Balancing load balancer, and an Amazon Relational Database Service (Amazon RDS) database instance in your template. You create a stack by submitting the template you created, and CloudFormation automatically creates all of the resources for you.

Change Sets

You update a stack if you need to make changes to the running resources in it. You can create a changeset, which is a summary of your proposed modifications, before making changes to your resources. Before adopting changes, you can use changesets to see how they will affect your running resources, especially key resources.
If you rename an Amazon RDS database instance, for example, CloudFormation will build a new database and remove the old one. Unless you’ve already backed up the data in the old database, you’ll lose it. If you create a changeset, you’ll notice that your update will result in the replacement of your database.

How to Install AWS CloudFormation?

Follow the below-mentioned steps for installing the AWS CloudFormation:

Step 1: Pick a template

To begin, you’ll need a template that describes the resources you’d like to include in your stack. You’ll utilize an already-made sample template for this stage. The sample template creates a basic WordPress blog that uses a single Amazon EC2 instance with a local MySQL database for storage. The template also creates an Amazon EC2 security group to control firewall settings for the Amazon EC2 instance.

Step 2: Make sure you have prepared any required items for the stack

Before you generate a stack from a template, make sure that all of the template’s dependant resources are available. Both current AWS resources and resources declared in the template can be used or referred to by a template. CloudFormation takes care of inspecting references to resources in the template, as well as existing resource references to guarantee that they exist in the area where the stack is being created. Stack construction fails if your template refers to a dependent resource that does not exist.

Step 3: Create the stack

Let’s establish a stack using the WordPress template now that you have a valid key pair. To create the WordPress stack

  1. Sign in to the AWS Management Console and open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation.
  2. If this is a new CloudFormation account, choose Create New Stack. Otherwise, choose Create Stack.
  3. In the Template section, select Specify an Amazon S3 Template URL to type or paste the URL for the sample WordPress template, and then choose Next:https://s3.us-west-2.amazonaws.com/cloudformation-templates-us-west-2/WordPress_Single_Instance.template
  4. Under the Specify Details section, in the Name field, type a stack name. Use MyWPTestStack for this example. There can’t be any spaces in the stack name.
  5. The parameters from the template’s Parameters section will appear on the Specify Parameters page. All options that don’t have default values, such as DBUser, DBPassword, DBRootPassword, and KeyName, must have values. Enter the name of a legitimate Amazon EC2 pair in the same region as the stack in the KeyName box.
  6. Select Next.
  7. We won’t use any tags in this instance. Select Next. Tags, or key-value pairs, can aid in the identification of your stacks. See Adding tags to your CloudFormation stack for additional details.
  8. Examine the stack’s information. Choose Create when you’re happy with the options.

How does AWS CloudFormation work?

AWS CloudFormation performs underlying service calls to AWS to provision and configures your resources when you create a stack. Only activities that you have the authority to execute can be performed by CloudFormation. To use CloudFormation to build EC2 instances, for example, you’ll need access to create instances. When you delete stacks with instances, you’ll need equivalent permissions to terminate instances. To handle permissions, you use AWS Identity and Access Management (IAM).

Your template declares all of the calls that CloudFormation does. Let’s say you have a template that describes an EC2 instance with the instance type t1.micro. CloudFormation invokes the Amazon EC2 creates instance API and defines the instance type as t1.micro when you use that template to create a stack. The CloudFormation procedure for constructing stacks is depicted in the diagram below.

AWS CloudFormation stack daigram

Source: Microsoft

Follow the below-mentioned steps:

  1. Create or change a CloudFormation template in JSON or YAML format using the AWS CloudFormation Designer or your own text editor. You can also use a template that is given. The CloudFormation template specifies which resources you want and how they should be configured. Let’s say you wish to set up an Amazon EC2 instance. As seen in the following example, your template can declare an Amazon EC2 instance and define its properties:

2. The template can be saved locally or in an S3 bucket. If you made a template, save it with a.json,.yaml, or.txt file extension.

3. Specify the location of your template file, such as a path on your local computer or an Amazon S3 URL, when creating a CloudFormation stack. You can specify input values when you create the stack if the template contains parameters.

4. CloudFormation creates and configures resources by interacting with the AWS services indicated in your template.

CloudFormation reports that your stack has been constructed after all of the resources have been created. After then, you can begin utilizing the resources in your stack. If CloudFormation fails to generate a stack, it undoes your changes by destroying the resources it produced.

How to Update a stack with change sets ?

You can change the stack’s template when you need to alter the resources in your stack. There’s no need to make a new stack and then delete the old one. Create a changeset by submitting a changed version of the original stack template, new input parameter values, or both to update a stack. CloudFormation creates a changeset by comparing the updated template to the original template. The suggested modifications are listed in the changeset. You can either execute the changeset to update your stack or build a new changeset after analyzing the changes. The method for upgrading a stack is depicted in the diagram below

How to Update a stack with change sets ?

Source: Microsoft

Follow the below-mentioned steps:

  1. AWS CloudFormation Designer or a text editor can be used to modify a CloudFormation stack template. Alter the value of the InstanceType attribute in the original stack’s template to change the instance type for an EC2 instance, for example.
  2. Locally or in an S3 bucket, save the CloudFormation template.
  3. Create a change set by specifying the stack to be updated as well as the location of the amended template, such as a local path or an Amazon S3 URL. When you construct the change set, you can give values for any parameters in the template.
  4. Examine the change set to ensure that CloudFormation makes the modifications you expect. Check whether CloudFormation will be able to replace any key stack resources, for example. You can make as many change sets as you need until all of the changes are in place.
  5. Put the change set you want to put to your stack into action. CloudFormation updates your stack by only updating the resources that you changed, and then notifies you that your stack has been updated correctly. If the stack updates fail, CloudFormation undoes the changes and returns the stack to its previous operational state.

How to Delete a stack?

  • When you remove a stack, you tell CloudFormation which stack you want to get rid of, and it deletes the stack along with all of its resources. Stacks can be deleted via the CloudFormation UI, API, or AWS CLI.
  • If you want to delete a stack but keep certain of its resources, you can use a deletion policy to keep those resources.
  • CloudFormation indicates that your stack has been successfully removed when all resources have been erased. The stack will not be destroyed if CloudFormation is unable to delete a resource. Until you can successfully destroy the stack, all resources that haven’t been deleted will remain.

To Conclude

These are only a few of the features of AWS CloudFormation. These insights go into greater detail about CloudFormation’s basic features and how easy it is for users to execute their apps. It automates industry best practices and scales your infrastructure globally. The nicest feature is that you can use CloudFormation in conjunction with other AWS services. Not only that, but you’ll be able to handle private and third-party resources as well.

So, if you’re planning to use AWS CloudFormation, it’s a good idea to learn more about it. Knowing what you’re about to integrate will help you tap into the full potential of AWS CloudFormation and achieve smooth application execution.

Menu