AWS CFT (Cloud Formation Template)
Deep Dive into Cloud Formation Templates, what CFT is, what IAC is (Infrastructure as Code), and the Difference between AWS CLI and AWS CFT, then we will see the characteristics and components of CFT, tips and tricks on this, the difference between CFT and Terraform.
AWS CFT (Cloud Formation Template) is a Template for cloud formation and managing infra.
CFT implements IAC (Infrastructure as Code) means you write code to create/manage infrastructure, making CFT more useful than CLI, CLI on the other hand is used for quick operations.
AWS CFT only supports AWS, it is written either in YAML or JSON formatting and it again works with AWS APIs. It should be Declarative and Versioned. We will discuss what is Declarative and Version in some time.
Terraform/Crossplane supports multiple cloud providers. AWS CFT acts as the middleman to take the code from the user and it hits the AWS API and performs actions.
Versioned means these templates can be tracked using GIT, version control basically. Declarative means what you see is what you have now what does this statement mean, by reading the template you should be able to know what is happening and how many resources are created or what management there are doing. There will be code reviews for the code that you write.
Features of CFT and Formats
Formats — CFT supports JSON and YAML, YAML is readable, idendation comments can be used. But in JSON, it is brackets; you need to understand what is happening in depth.
Features are not just Creating infrastructure, but also drift detection, Drift Defection is nothing but let’s say you have created an EC2 and S3 using CFT and then tomorrow another resource does some change in the S3 bucket, when you come to your CFT and run something then you will be notified of the change that has happened and what exact difference is from the infrastructure you created is also visible with which you can perform necessary actions to it.
You can go to AWS CFT from CLI or UI, navigate to Stack, create Stack, and import the YAML from your local system.
{
"AWSTemplateFormatVersion" : "version date",
"Description" : "JSON string",
"Metadata" : {
template metadata
},
"Parameters" : {
set of parameters
},
"Rules" : {
set of rules
},
"Mappings" : {
set of mappings
},
"Conditions" : {
set of conditions
},
"Transform" : {
set of transforms
},
"Resources" : {
set of resources
},
"Outputs" : {
set of outputs
}
}Practical — Creation of CloudFormation Template
Get Sailesh Ramesh’s stories in your inbox
Join Medium for free to get updates from this writer.
Let’s build the template from Application Composer — it is easy and very interesting
Once you select Build from Application Composer — you can drag and drop resources on the canvas and the template will be auto-generated you can also choose if you want it in YAML or JSON format.
To check the template — See you have the toggle to select the format you want as well, click on create template and it will automatically be imported to your cloud formation window
The template would be stored in s3 and you can verify it by the URL
Complete all the steps like giving the stack details, configuring the stack options and finally reviewing and creating it. Verify the same by going to the service, in our case it is an S3 bucket.
Drifts in CloudFormation
The basic idea is that if there is some difference between your cloud formation code and the actual entity, you can get to know it by using Drifts. In our example let us delete the S3 bucket created through CFT.
Before deleting the S3 Bucket
After Deleting S3 Bucket
Now, to understand drifting better, let’s enable versioning let’s create a template in the local, select Choose an existing template upload a template file and go ahead with the configuration below. Verify that the bucket versioning is enabled in the S3 bucket.
Resources:
S3Bucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: "demo.aws.versioning.example.com"
VersioningConfiguration:
Status: "Enabled"Now, you manually change Bucket Versioning to Suspended. Let’s see the exact change that happened.
Thank you for reading so far
Feel Free to follow me on LinkedIN
Regards, Sailesh Ramesh









