Pages

Sunday, July 7, 2019

Cloud Formation - Creating your First Template

Infrastructure as  a Code also referred as IaC , is a type of IT setup where developers or operation teams automate the process of provisioning or managing a technology stack for an application rather then manually setting up the whole technology stack.The automation is done by software. Hence this is sometimes referred to as programmable or software defined infrastructure.

AWS cloudformation is a service that helps in model and setup aws resources so that we can spend less time managing those resources and more time in focusing the application development. Cformation can help us in,
Simplifying the infrastructure management
Quickly replication of infrastructure
Easily Controlling and tracking changes to the infrastructure

In this article we will see the basics of cloudformation. 

1. In order to automate things in aws using cloudformation a template needs to be written. The template is basically a JSON-format text file that describes the aws infrastructure that we are going to create or manage

2. The first character in the CloudFormation template must be an open brace ({), and the last character must be a closed brace (})

3. The template contains several sections like
Description
Metadata
Parameters
Mappings
Conditionals
Resources
AWSTemplateFormatVersion

4. The Resources section is the most important area where we describe the infrastructure that we want to create or manage

Since we are writing Cformation template for the first time, we will keep it simple. We will use the resource section to create a s3 bucket.

The syntax for the resource sections looks like below. 

{
    "Resources" : {
        "Name-of-your-bucket" : {
            "Type" : "resource type"
            }
        }
}

Since the template starts with an open brace and ends with close brace we have them in the file. In between the braces we will define the instructions for creating the resources.

The resource type indicates that type of resource that we are creating or managing. For example, the resource type AWS::EC2::Instance talks about the Ec2 resource. We can get the list of resources from the Aws Resource type references page.

Name of the Bucket - simplesample-bucket
Resource type - AWS::S3::Bucket

Now our complete template looks like below.
{
"Resources" : {
    "simplesamplebucket" : {
       "Type" : "AWS::S3::Bucket"
       }
    }
}

Save it in a 00-s3-bucket.json. Now login to your aws console -> cloudformation -> create a Stack
Choose the “upload a template file” and select the above created file and upload. Once successfully uploaded and validated,it gives us the details of the s3 bucket at the bottom. 

In the next page enter the stack name. In the next page it asks for the stack options where you can provide more details according to your requirements. I am leaving them alone as of now for the article purpose. It asks to review the stack in the final page, once we say create it starts creating the infrastructure that we defined. If all has gone well you should see “CREATE IN PROGRESS” and “CREATE_COMPLETE” when finished like below,

It takes a few seconds based on the infra you are creating and compleates. Now we can go to the s3 service and see our bucket is created successfully or not.

Hope this gives you some understanding of the cloudformation.

No comments :

Post a Comment