Write a CloudFormation Template In AWS – AWS CloudFormation

In this tutorial, we will see basics of CloudFormation as What is CloudFormation, Why CloudFormation and its Template Sections. Also we will see how to write a CloudFormation Template in AWS to create S3 bucket.

What is CloudFormation:

It’s an AWS Service which help to provision AWS resource predicatively and reputably, enable you to create or delete collection of resource as a single unit which refer to as a Stack.


Why CloudFormation:

Following are the advantages why peoples should use CloudFormation in AWS.

  1. Simplify infrastructure management
  2. Keep Infrastructure as a code
  3. Quickly replicate your infrastructure
  4. Track changes of your infra structure


CloudFormation Template Sections:

CloudFormation template is a JSON or YAML based text file that describes your AWS infrastructure. Template can include several major sections:

AWSTemplateFormatVersion (optional):  Section  identifies the capabilities of the template. The latest template format version is 2010-09-09 and is currently the only valid value.

Description(optional): Describe about purpose and use case of this particular template

Metadata(optional) :  Describe the about each resources used in the template, Some AWS CloudFormation features retrieve settings or configuration information that you define from the Metadatasection.

Parameters(optional):  section to customize your templates. Parameters enable you to input custom values to your template each time you create or update a stack.

Mappings(optional): section matches a key to a corresponding set of named values

Condition(optional): s section includes statements that define when a resource is created or when a property is defined. For example, you can compare whether a value is equal to another value. Based on the result of that condition, you can conditionally create resources.

Resources ( Required) : Resources in the minimum require section for a template, section contains reference information for all AWS resources that are supported by AWS CloudFormation

Resource Section:

Here we will see main required section i.e. Resources section

"Resources" : {
    "Logical ID" : {
         "Type" : "Resource type",
        "Properties" : {
            Set of properties

Logical ID: Logical name of the resource just to use inside the template to refer other part of the template

Type: The resource type identifies the type of resource that you are declaring.  For example, AWS::EC2::Instancedeclares an EC2 instance.

Resource properties:

Resource properties are additional options that you can specify for a resource

"Resources" : {
    "MyEC2Instance" : {
        "Type" : "AWS::EC2::Instance",
        "Properties" : {
            "ImageId" : "ami-2f726546"


Write a simple cloudFormation template to Create a S3 Bucket

Sample example of cloudformation template to create s3 bucket:
    "AWSTemplateFormatVersion" : "2010-09-09",
    "Description" : "Create a S3 Bucket called MyBucket",
    "Resources" : {
        "bucket1": {
            "Type": "AWS::S3::Bucket",
            "Properties": {
                "BucketName": "MyBucket"




Vinoth Kumar

Working as Devops Practitioner.

More Posts

Follow Me:

Vinoth Kumar

Working as Devops Practitioner.