AWSTemplateFormatVersiondefines the version of the CloudFormation template.
Descriptionis a brief description of the template's contents and behaviour.
Metadatais arbitrary YAML associated with the template.
Parametersis a name-indexed map of up to 60 inputs to the template, which can be validated.
Descriptionprovides a human-readable explanation of the input's use.
Typedefines the related type, e.g.
CommaDelimitedList(of strings) or a resource property for a pre-existing resource, such as
ConstraintDescriptiondescribes the input's format.
Defaultis an optional default value.
AllowedValuesis an optional list of enum values.
AllowedPatternis an optional Regular Expression (Private).
MaxLengthconstrain string lengths.
Mappingsserve as lookup tables. They can't contain references, as they're computed statically, but you can index into one using a parameter.
Conditionscontains a Resource ID indexed map of conditions in which different resources will or will not be created, using intrinsic functions to express logic.
Transformsdefine one or more macros CloudFormation should apply when processing the template, e.g. to
Includeresources from external files hosted in an S3 bucket.
Resourcesis a map of defined resources, indexed by a name relevant only in the template:
Typecontains the CloudFormation resource type, e.g.
Propertiesis optional for resources that have sensible defaults.
Outputslet a Stack emit up to 60 values post-creation or update, allowing other Stacks to reference them. They need a
Intrinsic functions allow representing lightweight logical operations using the CloudFormation template syntax. Some common functions:
Fn::FindInMap [MyMap, !Ref "MyParam", MyProp]gets the attribute
MyPropfrom the key in
MyMapmatching the value of the
Fn::GetAttgets an attribute from a resource defined elsewhere in the template.
Fn::Join String List<String>concatenates strings.
Fn::Sub String Mapsubstitutes map keys for their values.
Refsubstitutes a resource's ID or property, a property from a parameter or another resource defined in the template.
Calling intrinsic functions
There are multiple syntaxes for calling intrinsic functions:
# Long syntax
# Short syntax
Name: !Join ["x", "y", "z"]
CloudFormation deployments are called Stacks. Their content and status is managed in the CloudFormation service, allowing Stacks to be managed from the CloudFormation section of the Console.
Stack provisioning events have statuses:
CloudFormation templates can either be stored outside of AWS and uploaded to the CloudFormation service just during updates, or stored in an S3 bucket where they can be freely fetched and versioned (generally preferred).
Stacks can be updated in one of two ways:
- directly, good for rapid deployment of changes, but with poor visibility and higher risk of erroneous modifications to important resources; or
- via change sets, allowing previewing in the form of JSON change summaries.
Exports allow one CloudFormation Stack to provide output values that may be sourced by other CloudFormation Stacks deployed to the same region and account.
StackSets allow management of Stacks across multiple accounts and regions in a single operation.
The Designer provides a graphical representation of a template.
Custom resources can be defined in CloudFormation. Handlers must consume a request, validate that it's valid, perform a provisioning operation and write a result to a pre-signed S3 object for CloudFormation to pick up. Handlers are commonly hosted on AWS Lambda, using SNS notifications as triggers.
Requests are comprised of:
RequestTypedefines the action being taken, either
ResourcePropertiesis a map of values specific to the changing resource.
ResponseUrlis a pre-signed (what) S3 URL where CloudFormation will seek a response.
Responses are comprised of:
RequestIdidentifies the operation and must be included.
Stackidentifies the Stack and must be included.
FAILUREdepending upon the result.
Reasonis a string describing the fault, required on failure.
LogicalResourceIdis a developer-chosen name for the resource.
PhysicalResourceIdlets us track a resource's lifetime over Stack provisioning operations: empty on
CREATE, the value returned during
UPDATEunless the resource is replaced, the last known value during
ResourceDataoptionally defines the outputs available as properties to other resources in the Stack.
A custom resource:
# Where should the request be sent? Lambda function or SNS topic.