AWS Cloud Formation

AWS CloudFormation is a cloud builder service that helps you model and set up your Amazon Web Services resources so that you can spend less time managing those resources and more time focusing on your applications that run in AWS. For this you need to create a template that describes all the AWS resources that you want, like Amazon EC2 instances that you want, Amazon VPC and subnet details and so on. AWS CloudFormation takes care of provisioning and configuring those resources for you. You don't need to individually create and configure AWS resources and figure out what's dependent on what, AWS CloudFormation handles all of that.

AWS CloudFormation is available at no additional charge. You will be billed only the normal rates for the AWS resources like EC2, RDS, LB and so on that AWS CloudFormation creates and your application and resources use.



The following are the two main parts of Cloud Formation.

Cloud Formation Template:

A template is a JSON-formatted text file that describes your AWS infrastructure. Templates include several major sections. The Resources section is the only section that is required. You can use AWS CloudFormation's sample templates or create your own templates to describe the AWS resources and any associated dependencies or runtime parameters required to run your application.


Cloud Formation Stack

The Cloud Formation Stack provides the ability to deploy, update and delete a template and its associated collection of resources by using the AWS Management Console, AWS Command Line Interface or APIs.

In this tutorial we are launching an EC2 instance using Cloud Formation.

  1. Create a Cloud Formation Template using the AWS document. Or download the sample document from the following link.

    Sample Templates

    *For this LAB we are using a custom template.

    Cloud Formation LAB

  2. Login to the AWS Console and select Amazon Cloud Formation service.



  3. Create a new Stack by selecting the Create Stack option.


  4. Type Stack Name and choose Cloud Formation Template that you created in Step 1.

    Note: You can upload a template on Amazon S3 and provide the link in this step.



  5. Select Cloud Formation Template file, open it and click on the Next button.



  6. In Template we can add multiple parameters. Parameters are usually used to get details or values from the user. For example, taking a Key Pair Name, VPC CIDR range and so on. Which can vary time to time or depend on various situations.

    For this LAB we are using one parameter for launching the EC2 instance, in other words Key Pair name. Choose Key Pair and click on the Next button. Please refer to the AWS Key Pair document for creating a Key Pair in your AWS account.

  7. You can add common TAGs to all the resources that we will be created using AWS CloudFormation. Add a TAG Key & Value and click on "Next".



  8. Review all the details and create the Stack.



  9. Check the event details to verify that the Stack was completed.



  10. You can check the output tab to complete the resource details.



  11. Go to the EC2 dashboard and check the instance. A new instance is created by Cloud Formation and it's in a running state now. Now you can connect this instance using Putty or any other tool over the SSH – 22 port. You can also stop and start an instance as needed.



  12. We can create N - number of resources using a single Cloud Formation Template and Stack and hence cleaning all the resources created by a specific Cloud Formation is important. To delete all
    resources created by a specific stack, select Stack from the CloudFormation dashboard and select the Delete Stack button.



  13. It will take time to delete all the resources. You can check the current status by selecting the Event tab.

AWS Cloud Formation supports nearly all AWS Resources. You can create a template for any of the following AWS Resources.


Next Recommended Readings