AWS CloudFormation

AWS CloudFormation gives developers and systems administrators an easy way to create and manage a collection of related AWS resources, provisioning and updating them in an orderly and predictable fashion.

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. You don’t need to figure out the order in which AWS services need to be provisioned or the subtleties of how to make those dependencies work. CloudFormation takes care of this for you. Once deployed, you can modify and update the AWS resources in a controlled and predictable way allowing you to version control your AWS infrastructure in the same way as you version control your software.

You can deploy and update a template and its associated collection of resources (called a stack) via the AWS Management Console, CloudFormation command line tools or APIs. CloudFormation is available at no additional charge, and you pay only for the AWS resources needed to run your applications.

Easy to sign up,
pay only for what you use
Sign Up

This page contains the following categories of information. Click to jump down:

AWS CloudFormation Functionality

To use AWS CloudFormation, you simply:

  • Sign-up for AWS CloudFormation. You will automatically be signed up for all the services supported by AWS CloudFormation. You will only be charged for resources that you use. Once signed up, you can begin using AWS CloudFormation via the AWS Management Console, the command line tools or the APIs.
  • Create a CloudFormation stack to provision the collection of resources needed by your application. You do this in two simple steps: First, select the template you want to use in the CloudFormation tab of the AWS Management Console. AWS CloudFormation comes with sample templates for popular open source applications that you can deploy immediately to get started. Our sample templates illustrate how to interconnect and use multiple AWS resources in concert, following best practices for geographic redundancy, scale out, and alarming. You can also load your own custom templates that you may store in Amazon Simple Storage Service (Amazon S3) or on your local hard drive. Second, determine if you want to customize your stack by overriding template parameters (such as database or application usernames, passwords, port numbers, Amazon EC2 instance types, etc.), or simply accept the default values supplied by the template author. Once complete, AWS CloudFormation takes care of provisioning the AWS resources, creating the stack for you.
  • View all the AWS resources contained in each of your stacks in the AWS Management Console.
  • Create additional stacks (if needed) by simply using existing templates you’ve created, choosing from one of our sample templates, or creating a new one from scratch. Since templates are text files that can be created and managed outside of CloudFormation, you can share them easily through email, source control repositories, or services such as Amazon S3.
  • Make changes and updates to your running stacks allowing you to react to the software updates and configuration changes needed to manage your application over its lifetime. You do this in 2 simple steps: First modify your template with the configuration changes required for all of the resources in the stack. You can use your version control and change management best practices for your templates allowing you to manage changes to the configuration of your AWS infrastructure in the same way as you manage changes to the software running on it. Second, submit the updated template to AWS CloudFormation via the AWS Management Console, the command line tools or the APIs. AWS CloudFormation takes care of the rest, making the configuration changes to your stack in a controlled and predictable way.

Service Highlights

Supports a Wide Range of AWS Resources – AWS CloudFormation supports many AWS resources, allowing you to build a highly available, reliable, and scalable AWS infrastructure for your application needs. Today AWS CloudFormation supports:

  • Amazon EC2 Instances
    (On-Demand Instances, Spot Instances, and Reserved Instances)
  • Amazon Elastic Block Store (EBS) Volumes
  • Elastic Load Balancers
  • Elastic IP Addresses
  • Amazon EC2 Security Groups
  • Auto Scaling Groups
  • Amazon Relational Database Service (RDS) Instances
  • Amazon RDS Security Groups
  • Amazon ElastiCache Clusters
  • Amazon ElastiCache Security Groups
  • Amazon ElastiCache Parameter Groups
  • AWS Elastic Beanstalk
  • Amazon CloudWatch Alarms

  • Amazon Simple Storage Service (S3) Buckets
  • Amazon Simple DB Domains
  • Amazon Simple Queue Service (SQS) Queues
  • Amazon Simple Notification Service (SNS) Topics
  • Amazon SNS Subscriptions
  • Amazon Route 53 DNS Records
  • Amazon CloudFront Distributions and Multi-Origin support
  • AWS Identity and Access Management users and groups
  • AWS Identify and Access Management policies
  • Amazon Virtual Private Cloud VPCs, Subnets, Gateways, Route Tables and Network ACLs
  • Amazon DynamoDB Tables


Easy to Use – CloudFormation makes it easy to organize a collection of AWS resources you want to deploy and lets you describe any dependencies or special parameters that can be passed in at runtime. You don’t need to figure out the order in which AWS services need to be provisioned or the subtleties of how to make the dependencies work. CloudFormation takes care of this for you. You can use one of the many CloudFormation sample templates -- either verbatim or as a starting point -- or create your own.

AWS CloudFormation comes today with the following ready-to-run sample templates:

  • WordPress (blog)
  • Tracks (project tracking)
  • Gollum (wiki used by GitHub)
  • Drupal (content management)

  • Joomla (content management)
  • Insoshi (social apps)
  • Redmine (project mgmt)
  • Many simple templates to show use of individual AWS resources and features


No Need to Reinvent the Wheel – A template can be used repeatedly to create identical copies of the same stack (or to use as a foundation to start a new stack). You can capture and control region-specific infrastructure variations such as Amazon EC2 AMIs, as well as Amazon Elastic Block Store (EBS) and Amazon RDS snapshot names.

Transparent and Open – Templates are simple JSON formatted text files that can be placed under your normal source control mechanisms, stored in private or public locations such as Amazon S3 and exchanged via email. AWS CloudFormation allows you to "open the hood," to see exactly which AWS resources are used to create a stack. You retain full control and have the ability to modify any of the AWS resources created as part of a stack.

Declarative and Flexible – To create the infrastructure you want, you enumerate what AWS resources, configuration values and interconnections you need in a template and then let AWS CloudFormation do the rest with a few simple clicks in the AWS Management Console, via the command line tools or by calling the APIs. You won’t have to recall the details of how to create and interconnect the respective AWS resources via their service APIs; AWS CloudFormation does this for you. You also don’t need to write a template from scratch if you prefer to start with one of the many sample templates that come with AWS CloudFormation.

Customized via Parameters – Parameters allow you to customize aspects of your template at runtime, when the stack is built. For example, the RDS database size, EC2 instance types, database and webserver port numbers can be passed to AWS CloudFormation when a stack is created. You can also use a parameterized template to create multiple stacks that may differ in a controlled way. For example, your Amazon EC2 instance types, Amazon CloudWatch alarm thresholds and Amazon Relational Database Service (Amazon RDS) read-replica settings may differ between AWS regions if you receive more customer traffic in the US than in Europe. You can use template parameters to tune the settings and thresholds in each region separately and still be sure that the application is deployed consistently across the regions.

Integration Ready – AWS CloudFormation publishes progress events through the AWS Simple Notification Service (SNS). This allows you to track stack creation and deletion progress via e-mail, and integrate with other processes programmatically.

No Extra Charge – AWS CloudFormation is available at no additional charge. You will be billed only the normal rates for the AWS resources that are created by AWS CloudFormation and used by your application.


Pricing

There is no additional charge for AWS CloudFormation. You pay for AWS resources (e.g. EC2 instances, Elastic Load Balancers, etc.) created using AWS CloudFormation in the same manner as if you created them manually.

In order to avoid having you sign up individually for all services supported by AWS CloudFormation, we automatically sign you up for all these services when you sign up for AWS CloudFormation. This makes it easy for you to use the AWS CloudFormation sample templates without having to manually check that you are enabled for the respective AWS services. With all AWS services, you only pay for what you use, as you use it; there are no minimum fees and no required upfront commitments.


Detailed Description

Creating AWS CloudFormation Templates

A template is a JSON (Javascript Object Notation) formatted text file that describes the AWS infrastructure needed to execute an application or service along with any inter-connection between them. Templates concisely capture resource relationships, such as EC2 instances that must be associated with an Elastic 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. The template can be parameterized to enable a single template to be used for many infrastructure deployments that have different configuration values, such as how many instances to spin up for the application. Templates also provide output properties that can be used to easily communicate configuration or the results of deploying the template back to the user. For example, when instantiated, a template may provide the URL of the Elastic Load Balancer endpoint the customer should use to connect to the newly instantiated application. 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.

You provide the template to the CreateStack operation in the AWS Console, the command line tool or API. There is no need to register the template with AWS CloudFormation beforehand. 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.

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

The collection of resources that result from instantiating a template is known as a stack. A stack is created by supplying a template and any required parameters to the AWS CloudFormation service. Based on the template, the service determines what AWS resources need to be created and in what order. The order is determined by the dependencies specified between the resources declared in the template. Some of these dependencies are implicit, for example, in order to associate an EBS volume with an EC2 instance, the name of the EBS volume must be passed to the instance. For that to happen, the EBS volume must be created first so that it is given a name or identifier. In other cases, the dependency is explicit. For example, if an application is deployed using an Auto Scaling group and needs to access an Amazon Relational Database Service instance, the database instance must be created before the EC2 instances are created. In this case the template author can define a dependency between the resources, ensuring one is created before the other.

Stacks are created, updated and deleted using the AWS CloudFormation service. During stack creation, AWS CloudFormation records the mapping from the logical name given in the template (e.g. ‘myServer’) to the actual name of the resource that is instantiated (e.g. EC2 instance name ‘i-19d3ac161’). The stack creation status and resource name mappings are available via a simple API. In addition, AWS CloudFormation tags EC2 resources, such as instances and EBS volumes, with the stack name.

Stacks are updated by supplying a template that contains 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 that changes through the different resources in your stack. In many cases, the changes will be made without impacting your running application, however, if a change cannot be made dyanmically (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 is sure that the full update will be successful.

A stack will either be created or updated in its entirety or rolled back if it cannot be fully instantiated or modified. During stack creation, for debugging purposes, the rollback operation can be disabled and manually initiated at a later time.

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. 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: Start the creation of a new stack. The input parameters to the call include the stack name and a filename (or S3 URL) for the source template. If the process of creating the stack completes successfully, the stack will be in the CREATE_COMPLETE state. If the stack creation fails, AWS CloudFormation will delete previously created resources, unless the user specified a flag to retain these elements for debugging purposes.
  • ListStacks: Lists all of the stacks in your account. This can be used to view the set of stacks and their current status indicating whether there is an update or create operation in progress or the stack is ready.
  • ListStackResources: Lists all the AWS resource names and identifiers that were created as part of creating a stack. This can be used to view the resources created by a stack or it can be used by an AWS CloudFormation-aware application to understand the environment in which it is deployed.
  • DescribeStackEvents: Lists all the AWS CloudFormation generated operations and events for a stack to allow you to see how creation or deletion is progressing.
  • UpdateStack: Start the update process for an existing stack. The input parameters to the call include the stack name and a filename (or S3 URL) for the updated template. If the process of updating the stack completes successfully, the stack will be in the UPDATE_COMPLETE state. If the stack update fails, AWS CloudFormation will rollback any resource changes that have been made so that the stack is returned to state described in the original template.

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"
    }
} 

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.

The CloudFormation scripts can be used standalone 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 whitepapers

Documentation

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.


Intended Usage and Restrictions

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

©2013, Amazon Web Services, Inc. or its affiliates. All rights reserved.