๐ Introduction
AWS CloudFormation simplifies this process by allowing you to define and provision your AWS infrastructure using code. This service enables you to create, update, and manage a collection of AWS resources.
๐ธWhat is AWS CloudFormation
AWS CloudFormation is a service provided by Amazon Web Services (AWS) that helps automate the deployment and management of AWS resources in a consistent and repeatable manner. It allows you to define your infrastructure as code using a JSON or YAML template format, called a CloudFormation template.
With CloudFormation, you can create, update, and delete a collection of AWS resources together as a single unit, referred to as a stack. These resources can include EC2 instances, S3 buckets, databases, load balancers, security groups, and more.
๐ธKey components of AWS CloudFormation include:
1. Templates: JSON or YAML files that describe the AWS resources and their configurations. These templates define the infrastructure in a declarative way.
2. Stacks: A collection of AWS resources that are created and managed as a single unit. Stacks are created based on the templates and can be updated or deleted as needed.
3. Resources: The individual AWS components defined within a CloudFormation template, such as EC2 instances, S3 buckets, RDS databases, etc.
4. Parameters and Outputs: Parameters allow customization of template inputs, while outputs provide information about the created resources after the stack creation.
5. Change Sets: A way to preview changes before applying them to a stack. Change sets help identify any modifications that might occur when updating a stack.
๐ธUsing CloudFormation offers several advantages, such as:
Infrastructure as Code (IaC): Infrastructure can be managed and version- controlled as code, enabling easier replication and collaboration.
Automation: Simplifies and automates the deployment and management of resources, reducing manual effort and potential errors.
Consistency and Reproducibility: Ensures consistent deployments across different environments (e.g., development, testing, production).
Resource Dependency Management: Handles dependencies between resources automatically.
๐ธNow, we will see how to create an S3 bucket
Search CloudFormation in search-box and click on Create stack.
If you choose "Choose an existing template," you can write code in either YAML or JSON to create resources like an S3 bucket, EC2 instance, etc. If you select "Build from application composer," you can create resources by dragging and dropping images of the components you want to create, as I have done below.
This is how you can create s3 bucket by dragging & dropping images.
After that click on next.
Write a stack name.
Now click on submit.
After that, you can see here that it shows "s3-bucket CREATE_COMPLETE," so you can go and check if the S3 bucket has been created or not.
If you want to create s3 bucket by selecting Choose an existing template so, the process is the same; you just need to write the code in YAML.
Resources:
MyS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: s3-bucket1
What if s3-bucket gets deleted
So, you can see i have in below picture i have deleted s3 bucket. Remember, I deleted the S3 bucket not the stack.
There is a option called as drifts, click on it and click on detect stack drift to see drift status
So, you can see "Drifted" in the drift status, which means the S3 bucket has been deleted or someone has deleted it.
AWS CloudFormation provides drift detection capabilities, which allow you to check whether your resources have drifted from their expected configurations.
Drift Status:
Drifted: Indicates that the actual configuration of the resource has changed from the configuration specified in the CloudFormation template.
In Sync: Indicates that the actual configuration of the resource matches the configuration specified in the CloudFormation template.
Not Checked: Indicates that drift detection has not been performed on the resource.
๐ Conclusion
CloudFormation provides a powerful way to manage infrastructure but requires an understanding of AWS service and the CloudFormation template structure to use it effectively.
Thanks for reading to the end; I hope you gained some knowledge.โค๏ธ๐