Greetings!
AWS CloudFormation is an infrastructure as code (IaC) solution by AWS to model, provision, and manage AWS resources. Thus, giving us more time to focus on our applications that run in AWS.
What we do is create a template in YAML or JSON format that describes all the resources we want to create, and CloudFormation takes to create it. We are free of manual work.
Without too much theory, let's create an S3 bucket using CloudFormation. We don't have to worry about notations when we get started.
You would see "CREATE_COMPLETE" event
Go to S3
You can see a bucket is created (ex: helloworlds3bucket-hellobucket-1lkr58xw19ai0)
Go to S3, and you can see "Publicly accessible" applied to the bucket.
A stack is a collection of AWS resources that you can manage as a single unit. In other words, you can create, update, or delete a collection of resources by creating, updating, or deleting stacks.
AWS CloudFormation is an infrastructure as code (IaC) solution by AWS to model, provision, and manage AWS resources. Thus, giving us more time to focus on our applications that run in AWS.
What we do is create a template in YAML or JSON format that describes all the resources we want to create, and CloudFormation takes to create it. We are free of manual work.
Without too much theory, let's create an S3 bucket using CloudFormation. We don't have to worry about notations when we get started.
Steps
- Define the CloudFormation template
- Upload it to AWS
An IaC S3 Bucket
First of all, let's create our template (cfn-s3.yml)Resources:
HelloBucket:
Type: AWS::S3::Bucket
Step
two is to upload this to AWS.- Go to AWS CloudFormation
- Click on Stacks
- Click on Create stack -> with new resources
- Choose "Template is ready"
- Choose "Upload a file"
- Select your cfn-s3.yml file
- Give a Stack name (HelloWorldS3Bucket)
- Click Next -> Next -> Create stack
You would see "CREATE_COMPLETE" event
Go to S3
You can see a bucket is created (ex: helloworlds3bucket-hellobucket-1lkr58xw19ai0)
Update the Bucket
Now, let's update our bucket with public readResources:
HelloBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
- Go to CloudFormation > Stacks > HelloWorldS3Bucket
- Choose "Replace current template"
- Click Next -> Next -> Update stack
Go to S3, and you can see "Publicly accessible" applied to the bucket.
Delete the Bucket
With CloudFormation, we do not have to delete resources one by one. Instead, we delete the stack we created, then CloudFormation will handle all deletions.- Go to Stacks
- Select your stack and click on delete
Stack
One word that bugged me when I got started is "Stack". AWS documentation has a better explanation.A stack is a collection of AWS resources that you can manage as a single unit. In other words, you can create, update, or delete a collection of resources by creating, updating, or deleting stacks.
Building Blocks
We used the "Resources" section in our S3 example as that is the only mandatory field. There are other components like Description, Transform, Metadata, Parameters, Mappings, Outputs, Conditionals, Rules, and helpers (References, Functions) we need to learn but let's learn as we go.Why do we use CloudFormation?
Let me grab a few notes from the documentation directly.- Simplify infrastructure management - Unlike our simple S3 bucket, a real application consists of many resources. Creating, and managing all these resources by hand is difficult and time-consuming. CloudFormation simplifies all these for us.
- Quickly replicate your infrastructure - We will have to create the same resources over and over for multiple stages, and environments. With CloudFormation we only need to re-use our template.
- Easily control and track changes to your infrastructure - When we create, update, delete, etc resources manually, we might do mistakes. Also, we might not remember all the things we did. Instead, we have all our changes in the CloudFormation template so that we can easily track our changes.
- Source control - As with any other IaC solution, we can have our changes under source control like git where others can review, and approve changes.
Comments
Post a Comment