CloudFormation Basics

CloudFormation Getting Started Guide

An AWS CloudFormation template begins with an open brace and ends with a close brace. Within those braces, you can declare six top level JSON objects: AWSTemplateFormatVersion, Description, Parameters, Mappings, Resources, and Outputs.

Naming Hierarchy
JSON Object->Eg.Resource->Attributes->Eg.Type & Properties->Eg. AWS::EC2::Instance->Resource Property Type->Eg. EC2 Tag

This is mostly required compared to all others. The Resources object contains the definitions of the AWS resources you want to create with the template.
The resource declaration begins with a string that specifies the logical name for the resource. As you’ll see, the logical name can be used to refer to resources within the template.

Each Resource has attributes – Type & Properties

A resource must have a Type attribute, which defines the kind of AWS resource you want to create. The Type attribute has a special format:
For example, the resource type for an Amazon S3 bucket is AWS::S3::Bucket.

    "Resources" : {
        "HelloBucket" : {
            "Type" : "AWS::S3::Bucket"



You use the Parameters object to declare values that can be passed to the template when you create the stack. A parameter is an effective way to specify sensitive information, such as user names and passwords, that you don’t want to store in the template itself. It is also a way to specify information that may be unique to the specific application or configuration you are deploying, for example, a domain name or instance type. When you create the WordPress stack later in this section, you’ll see the set of parameters declared in the template appear on the Specify Parameters page of the Create Stack wizard, where you can specify the parameters just before creating the stack.

The parameters are used in the template to specify values used in properties in the Amazon RDS DB Instance resource

Receiving User Input Using Input Parameters

You use mappings to declare conditional values that are evaluated in a similar manner as a switch statement. Usually The template uses mappings to select the correct Amazon machine image (AMI) for the region and the architecture type for the instance type.

Outputs define custom values that are returned by the aws cloudformation describe-stacks command and in the AWS Management Console’s Outputs tab after the stack is created. You can use output values to return information from the resources in the stack, such as the URL for a website created in the template.

Make sure you have a valid EC2 key pair, and make note of the Key Pair Name, before you create the stack.

CF Functions
AWS CloudFormation has a number of intrinsic functions that you can use to refer to other resources and their properties. You can use the Ref function to refer to an identifying property of a resource. Frequently, this is the physical name of the resource; however, sometimes it can be an identifier, such as the IP address for an AWS::EC2::EIP

Explaining the Ref Function :

The Ref function is handy if the parameter or the value returned for a resource is exactly what you want; however, you may need other attributes of a resource. For example, if you want to create a CloudFront distribution with an S3 origin, you need to specify the bucket location by using a DNS-style address. A number of resources have additional attributes whose values you can use in your template. To get these attributes, you use the Fn::GetAtt function.

Explaining the Fn:GetAtt :

New Features in CF –!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s