The best way to get started with AWS CloudFormation is to work through the Getting Started Guide, which is included in our technical documentation. Within a few minutes, you will be able to deploy one of the sample templates and start creating your own infrastructure configurations.
Introduction to AWS CloudFormation

CloudFormation templates have several advantages:

Follow a familiar format: A CloudFormation template is simply a JSON (JavaScript Object Notation) or YAML-formatted text file that describes the AWS infrastructure needed to run an application or service along with any interconnection between them.

Manage relationships: Templates concisely capture resource relationships, such as EC2 instances that must be associated with an Elastic Load Balancing load balancer, or the fact that an EBS volume must be in the same EC2 Availability Zone as the instance to which it is attached.

Use over and over: Using template parameters enable a single template to be used for many infrastructure deployments with different configuration values, such as how many instances to deploy for the application.

Get helpful feedback: Templates also provide output properties for communicating deployment results or configuration information back to the user. For example, when instantiated, a template may provide the URL of the Elastic Load Balancing endpoint the customer should use to connect to the newly instantiated application.

Avoid collisions: All AWS resources in a template are identified using logical names, allowing multiple stacks to be created from a template without fear of naming collisions between AWS resources.

Write and go: Use any method to launch a stack without having to register the template with AWS CloudFormation beforehand.

Visualize your stack: CloudFormation Designer lets you visualize your templates in a diagram. You can easily view your AWS resources and their relationships, and arrange their layout so that the diagram makes sense to you. You can edit the templates using the drag-and-drop interface and the integrated JSON editor. The modifications you make to the diagram automatically modify the template’s JSON.                                                                                                                                          

Look up resources: AWS CloudFormation retains a copy of the stack template so you can use the AWS Management Console, the command line tools or the APIs to look up the precise resource configurations that were applied during stack creation.

Automate: You have the option to automate template generation using a programming language or a tool of your choice. You also have the option to automate stack creation from the templates using the CloudFormation API, AWS SDKs, or AWS CLI.

A Template has the following high level JSON Structure:


    "Description" : "A text description for the template usage",

    "Parameters": {

        // A set of inputs used to customize the template per deployment


    "Resources" : {

        // The set of AWS resources and relationships between them


    "Outputs" : {

        // A set of values to be made visible to the stack creator


    "AWSTemplateFormatVersion" : "2010-09-09"


The following template is a simple example that shows how to create an EC2 instance:


    "Description" : "Create an EC2 instance running the Amazon Linux 32 bit AMI.",

    "Parameters" : {

        "KeyPair" : {

            "Description" : "The EC2 Key Pair to allow SSH access to the instance",

            "Type" : "String"



    "Resources" : {

        "Ec2Instance" : {

            "Type" : "AWS::EC2::Instance",

            "Properties" : {

                "KeyName" : { "Ref" : "KeyPair" },

                "ImageId" : "ami-3b355a52"




    "Outputs" : {

        "InstanceId" : {

            "Description" : "The InstanceId of the newly created EC2 instance",

            "Value" : {

                "Ref" : "Ec2Instance"




    "AWSTemplateFormatVersion" : "2010-09-09"


Using an AWS CloudFormation Template to Create and Manage a Stack

A stack is a collection of resources that result from instantiating a template. You create a stack by supplying a template and any required parameters to AWS CloudFormation. Based on the template and any dependencies specified in it, AWS CloudFormation determines what AWS resources need to be created and in what order.

To update a stack, you provide a template with the desired configuration of all of the resources in your stack. You can modify properties of the existing resources in your stack to react to changes in your environment or new application requirements. For example, you can change the alarm thresholds on your AWS CloudWatch alarms or update the AMI running on an instance in your stack. AWS CloudFormation takes care of rolling those changes through the different resources in your stack. In many cases, the changes will be made without affecting your running application. However, if a change cannot be made dynamically (such as updating the AMI on an EC2 instance), AWS CloudFormation will create a new resource and rewire it into the stack, deleting the old resource once the service has determined that the full update will be successful.

AWS CloudFormation will create or update a stack it in its entirety. If a stack cannot be created or updated in its entirety, AWS CloudFormation will roll it back. For debugging purposes, the rollback operation can be disabled and the stack create or update can be manually retried at a later time.

You can also use AWS CloudFormation Designer to create or modify a stack's template and then submit it to AWS CloudFormation to create or update the stack. AWS CloudFormation Designer is available within the AWS Management Console.

AWS CloudFormation can be easily accessed through the AWS Management Console, which gives you a point-and-click, web-based interface to deploy and manage stacks. You can create, delete, and update an application from inside the AWS Management Console in a few simple steps.

Working with the AWS CloudFormation API

AWS CloudFormation also provides a simple set of APIs that are easy to use and highly flexible. For a full list of the available AWS CloudFormation APIs, please see the AWS CloudFormation API Reference Guide. Some of the most commonly used APIs and their functionality are listed below:

CreateStack: Starts the creation of a new stack. The input parameters to the call include the stack name and a file name (or Amazon S3 URL) for the source template. If the process of creating the stack is completed successfully, the stack is in the CREATE_COMPLETE state. If the stack creation fails, AWS CloudFormation deletes previously created resources, unless the user specified a flag to retain these elements for debugging purposes.

ListStacks: Lists all stacks in your account. You can use this to view the set of stacks and their current status, such as whether the stack is being created or updated.

ListStackResources: Lists all the AWS resource names and identifiers that were created as part of creating a stack. In addition to providing you information, this call can be used by an AWS CloudFormation-aware application to understand its environment.

DescribeStackEvents: Lists all AWS CloudFormation generated operations and events for a stack so you can see how creation or deletion is progressing.

UpdateStack: Starts the update process for an existing stack. The input parameters to the call include the stack name and a file name (or Amazon S3 URL) for the updated template. If the process of updating the stack is completed successfully, the stack will be in the UPDATE_COMPLETE state. If the stack update fails, AWS CloudFormation rolls back any resource changes that have been made so that the stack is returned to state described in the original template.

AWS CloudFormation can also be used via the AWS SDKs and the AWS CLI.

AWS CloudFormation is integrated with the Amazon Simple Notification Service (Amazon SNS), allowing you to receive notifications as the creation, update and deletion of the stack progresses. In addition to providing you with status, this also allows other programs to become aware of events within CloudFormation and respond or even participate in the stack configuration process.

Working with AWS Resources

The AWS CloudFormation template is designed to leverage your existing experience with AWS. Each resource has a set of parameters with names that are identical to the names used to create the resources through their native API. The following template snippet shows how you define an Amazon EBS Volume. The logical name of the volume in the template is "myVolume", and its type is "AWS::EC2::Volume". The properties will look very familiar if you have used EBS volumes previously.

"myVolume" : {

    "Type" : "AWS::EC2::Volume",

    "Properties" : {

        "Size" : "10",

        "SnapshotId" : "snap-7b8fd361",

        "AvailabilityZone" : "us-east-1a"


Show less >>

Bootstrapping Applications and Handling Updates

AWS CloudFormation provides a number of helper scripts that can be deployed to your EC2 instances. These scripts provide a simple way to read resource metadata from your stack and use it to configure your application, deploy packages and files to your instance that are listed in your template, and react to stack updates such as changes to the configuration or updates to your application.

The following scripts are available:

cfn-get-metadata: Retrieve metadata attached to your resources in the template.

cfn-init: Download and install packages and files described in your template.

cfn-signal: Signal to the stack creation workflow that your application is up and running and ready to take traffic.

cfn-hup: A daemon to listen for stack updates that were initiated through the AWS console, command line tools or API directly and execute your application-specific hooks to react to those changes.

You can use CloudFormation scripts on their own or in conjunction with CloudInit, a feature available on the Amazon Linux AMI and some other Linux AMIs. For more details of bootstrapping applications and updating configuration, see the AWS CloudFormation developer resources.

Intended Usage and Restrictions

Your use of this service is subject to the Amazon Web Services Customer Agreement.


Learn more about AWS CloudFormation Pricing

Visit the AWS CloudFormation Pricing Page
Ready to build?
Get started with AWS CloudFormation
Have more questions?
Contact us