Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / cloud

AWS Cloud Formation

5.00/5 (2 votes)
21 Apr 2015CPOL3 min read 17.5K  
AWS Cloud Formation

Introduction

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 which you want like Amazon EC2 instances which you want, Amazon VPC and subnet details, etc., and 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, etc. that AWS CloudFormation creates and your application and resources use.

Two main part of Cloud Formation are given below.

1. 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.

Image 1

2. Cloud Formation Stack

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 EC2 instance using Cloud Formation.

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

    http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-sample-templates.html

    *For this LAB, we are using custom template.

    https://drive.google.com/file/d/0B9sysUQNwtqcaE9RS2xpUVpuRG8/view?usp=sharing

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

    Image 2

  3. Create new Stack by Selecting Create Stack option.

    Image 3

  4. Type Stack Name and choose Cloud Formation Template which you created in step 1.

    Note: You can upload Template on Amazon S3 and give link in this step.

    Image 4

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

    Image 5

  6. In Template, we can add multiple parameters. Parameters are mostly used to take details or values from user. For example, taking Key Pair Name, VPC CIDR range, etc. which can vary time to time or depend on various situations.

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

    Image 6

  7. You can add common TAGs to all resources, which we are going to create using AWS CloudFormation. Add TAG Key & Value and click on Next.

    Image 7

  8. Review all details and create Stack.

    Image 8

  9. Check event details to verify Stack completed or not.

    Image 9

  10. You can check output tab to completed resource details.

    Image 10

  11. Go to EC2 dashboard and check instance. New instance is created by Cloud Formation and it’s in running state now. Now you can connect this instance using Putty or any other tool over SSH – 22 port. Also you can Stop and Start instance as per your need.

    Image 11

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

    Image 12

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

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

Image 13

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)