AWS CloudFormation
User Guide (API Version 2010-05-15)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Templates

You describe your AWS infrastructure requirements in a template. A template is a text file whose format complies with the JSON standard. Because they are just text files, you can edit and manage them in your source control system with the rest of your source code. For more information about the JSON format, see http://www.json.org.

In the template, you can declare several main objects: the template's format version, its description, and the parameters, mappings, conditions, resources, and outputs you need to create your stack. The format version, descriptions, parameters, mappings and outputs are optional. You only need to declare one resource. The following depicts a valid template, which declares just a single resource with no properties.

{
    "Resources" : {
        "MyQueue" : {
            "Type" : "AWS::SQS::Queue",
            "Properties" : {
            }
        }
    }
}

A resource typically has a Properties section that contains the values needed to create that resource. If a resource does not require any properties to be declared, you can omit the Properties section of that resource.

To check your template file for syntax errors, you can use the aws cloudformation validate-template command.

Note

The aws cloudformation validate-template command is designed to check only the syntax of your template. It does not ensure that the property values you have specified for a resource are valid for that resource. Nor does it determine the number of resources that will exist when the stack is created.

To check the operational validity, you need to attempt to create the stack. There is no sandbox or test area for AWS CloudFormation stacks, so you are charged for the resources you create during testing.

Format Version

The template format version specifies the AWS CloudFormation template version against which the template was written.

Important

The template format version is not the same as the API or WSDL version. The template format version can change independently of the API and WSDL versions.

Optional Description

The optional Description property enables you to associate a free valid JSON text string with a template. Descriptions enable you to document a template.

Optional Parameters

Optional parameters are listed in the Parameters section. Parameters enable you to pass values to your template at runtime, and can be dereferenced in the Resources and Outputs sections of the template.

Most of the sample templates declare a Parameters section (see Example Templates). Parameters are described more fully in Parameters. Also, for technical details about the Parameters section format, see Parameters Declaration.

Optional Mappings

The optional Mappings section enables you to declare conditional values. Mappings can be dereferenced in the Resources and Outputs section using the intrinsic function Fn::FindInMap.

Two of sample templates declare a Mappings section (see Example Templates). Mappings are described more fully in Mappings. Also, for technical details about the Mappings section format, see Mappings Declaration.

Optional Conditions

The optional Conditions section is where you define conditions that control whether certain resources are created or whether certain resource properties are assigned a value during stack creation or update. For example, you could conditionally create a resource depending on whether the stack is for a production or test environment.

For more information about defining conditions, see Conditions.

Resources

The stack's member resources are listed in the Resources section. Each resource is listed separately, and specifies the resource properties necessary for creating that particular resource. Resources can be dereferenced in the Resources and Outputs sections. Their properties can be based on literals, resources, parameters, pseudo parameters, and intrinsic functions. For more information, see Resource Properties.

All of the sample templates declare a Resources section (see Example Templates). Resources are described more fully in Resources. For technical details about the Resources section format, see Resources Declaration.

Resource Properties

If a resource does not require any properties to be declared, you can omit the Properties section of that resource. Resource properties can be based on literals, resources, parameters, pseudo parameters, and intrinsic functions.

Most of the sample templates declare resources that have one or more properties (see Example Templates). Resource properties are described more fully in Resource Properties. Also, for technical details about the Properties section format, see Properties Declaration.

Optional Outputs

In the Outputs section, you can optionally define custom values that are returned in response to the aws cloudformation describe-stacks command. These output values can include information based on literals, resources, parameters, pseudo parameters, and intrinsic functions.

All the sample templates declare an Outputs section (see Example Templates). Outputs are described more fully in Outputs. Also, for technical details about the Outputs section format, see Outputs Declaration.