AWS CloudFormation is an AWS service that uses template files to automate the setup of AWS resources.
- AWS CloudFormation is a method of provisioning AWS infrastructure using code.
- AWS CloudFormation also provides a mechanism to manage the resources through their lifecycle.
- AWS CloudFormation is designed to help the developer to manage the AWS resources.
- It can also be described as infrastructure automation or Infrastructure-as-Code (IaC) tool because it can automate various Infrastructure-as-a-Service (IaaS) setups and deployments.
- CloudFormation defines the AWS resources in a structured text file in JSON or YAML formats, known as a CloudFormation template.
Why we need AWS CloudFormation:-
- When the number of services and products is doubled due to the necessity that AWS cannot handle all simultaneously, AWS CloudFormation comes into use.
- With AWS CloudFormation, the configuration changes can be made dynamically into the existing environment without any obstruction.
- Managing multiple AWS resources at a time is a time-consuming task.
- In the absence of AWS CloudFormation, the developers will focus their attention & time on building the infrastructure and the services, and they will focus less on the application development.
- Rebuilding any infrastructure product or service is a more challenging task, as everything has to be started from scratch.
- Now, this is where AWS CloudFormation comes in to handle this scenario.
Benefits & Features of using AWS CloudFormation:-
- AWS CloudFormation makes cloud service deployment and management faster and more efficient.
- With CloudFormation, we can integrate with DevOps and GitOps, like establishing a Git repository and deploying infrastructure through a CI/CD pipeline.
- It supports different resources of AWS.
- Templates can be used in CloudFormation StackSets to create, update and delete stacks across multiple AWS regions and accounts.
- CloudFormation CLI and Registry make it easy to manage third-party resources with CloudFormation.
- CloudFormation provisions the application resources in a safe and allows to build and rebuild the applications and infrastructure without having to perform manual actions or write custom scripts.
- We can create and modify templates using the interface and then alter template details with the help of the inbuilt JSON text editor.
- AWS CloudFormation comes along with AWS resources, so no extra charge has to be paid.
- CloudFormation performs to manage the stack most efficiently and rolls back changes automatically if errors are detected.
Disadvantages of not using AWS CloudFormation:-
- Many resources cannot be specified in an AWS CloudFormation template.
- Creating more than 200 resources in a single stack is impossible.
- The error description is not clear in some instances.
- Deleting some resources is tricky if they depend on other stacks.
- Some services take a lot of time to create, for at least 20 minutes. When some services fail, we have to retry the whole process again.
Working of AWS CloudFormation:-
- When creating a stack, AWS CloudFormation makes AWS provision and configures the resources.
- Developers can build a template based on various requirements and save it in the system.
- Using the AWS CloudFormation, developers can create a stack on the defined template.
- CloudFormation can only perform actions that the developer has permission to do.
- Creation of EC2 instances by using AWS CloudFormation, a developer has permission to create cases.
- CloudFormation templates can be saved locally or in an Amazon S3 bucket with a file extension like JSON, YAML, or .txt.
- By specifying the location of the template file, such as the path on the local computer or an Amazon S3 URL, developers can create AWS CloudFormation Stack.
- After creating all resources, CloudFormation reports that the stack has been made.
- If the creation of a stack fails, CloudFormation rolls back the changes by deleting the resources which have been created.
AWS CloudFormation Template Terms and Concepts:-
- If a developer wants to use AWS CloudFormation, he has to work with templates & stacks.
- The developer creates templates to describe the AWS resources and their properties.
- To understand the core concepts of CloudFormation, template structure, resources, variables, and functions must be known.
- AWS CloudFormation template is a text file explicitly formatted that outlines how AWS services or resources can be configured and deployed.
- Stack is a term that AWS uses to refer to a collection of numerous AWS resources, such as EC2, virtual machines, S3 storage, and IAM access controls that developers can manage together using a single template.
- AWS CloudFormation supports templates that are formatted by using JSON or YAML. Most other IaC tools use the same formatting languages, such as Kubernetes.
- Developers need to apply unique settings for each deployment by using these parameters. Parameters define custom values for each deployment that AWS CloudFormation will apply at runtime.
- Developers can fine-tune deployments by setting conditions that define conditional rules to proceed with each deployment.
- Anyone who wants to update a deployment using AWS CloudFormation can edit the template used to create the deployment. After that, they can create a change set which changes the updated template will apply before making any changes.
- There are different ways to get data into an AWS CloudFormation template, in which parameters will be primary. But those parameters may be unknown at deployment time. CloudFormation Functions allow AWS CloudFormation to retrieve data from resources deployed in the existing CloudFormation or from external resources in an AWS account.
Resources that can provide with AWS CloudFormation:-
Any AWS resources created from the AWS console can be provisioned within an AWS CloudFormation template. This includes some of the AWS resources like,
- EC2 Instances
- S3 Buckets
- AutoScaling Groups
- RDS Database Instances
- Amazon SQS Queues
- Elastic Load Balancers
- Network ACLs
- Route Tables
- AWS RDS Security Groups in a VPC
- EC2 Security Groups
Creation of AWS CloudFormation Stack from AWS Console:
- There are two ways to create a CloudFormation template.
- Using a pre-existing template as the foundation
- By writing an entirely new template from scratch
- To create an AWS CloudFormation stack from the AWS console, follow the below steps.
- The initial step is to navigate to the AWS CloudFormation Service on the AWS console, which can be found under "Management and Governance." Then click on the create stack.
- Here will take the existing template that can be uploaded to the AWS CloudFormation.
- Then we have to enter the template's location stored in the S3 bucket or use a sample template for the standard stack.
- In the next step, we need to mention the stack name and complete any parameters defined in the template.
- In the next step, we can specify up to 50 tag key/value pairs attached to all the resources created while creating the stack.
- Then we need to nominate an IAM role to use for the stack. If we do not specify a position, then the permissions will be based on the user credentials used to create the stack.
- Some advanced options include Stack Policy, Rollback Configuration, Notification Options, and Stack Creation Options.
- This JSON document defines the update actions that can be performed on nominated resources. This allows it to protect resources from unintentional updates during a stack update.
- This configuration allows specifying a CloudWatch alarm and period to monitor CloudFormation while creating or updating a stack. If the operation breaches an alarm threshold, then the update operation is rolled back.
- Here, developers can specify an SNS topic ARN to send notifications to.
Stack Creation Options:-
- Developers can specify here whether to roll back on failure or specify a stack creation timeout period and set the stack termination protection.
- The final step is to review the page that allows you to review and amend the options before selecting the "Create Stack."
- Then it will start to create the stack and report the status of each event as it is performed.
- Once it completes all the resources mentioned in the template, it will show a status of "CREATE_COMPLETE."
Need a consultation?
Drop us a line! We are here to answer your questions 24/7
Areas we serve
4100 NW Loop 410, Suite 200, San Antonio, Texas, USA 78229
7 Artisan Place Harrow, HA3 5DS
4th Floor, Timber Point, Prahaladnagar Road, Ahmedabad, Gujarat - 380015