Last updated: 2020-02-02
I will be posting tip sheets on a regular basis. These are called “living” tip sheets because they could be updated frequently, as I learn more.
The AWS Serverless Application Model (SAM) is a CloudFormation transformation macro used to ease the creation of serverless applications. We can think of it as a lightweight CloudFormation template with the core purpose of creating serverless infrastructure as code.
The documentation format of each attribute below is: Name – (YAML indentation level) Explanation
AWSTemplateFormatVersion
(1) This is the version of the CloudFormation template we’re writing for. AWS versions are normally in the format of a date (YYYY-MM-DD).Transform
(1) This is used to specify what CloudFormation macros (and, optionally, macro version) we are using. The macro for transforming this template from SAM into CloudFormation isAWS::Serverless-2016-10-31
. In this example,AWS::Serverless
is the macro we’re using (Serverless; that is SAM), and2016-10-31
is the version. AWS versions are normally in the format of a date (YYYY-MM-DD). Resource names (like macros) are delimited by a double colon (::).Description
(1) Comments describing the template. This setting must follow theAWSTemplateFormatVersion
setting.Mappings
(1) This allows us to create key/value pairs of data that we can use throughout our template. Under this, we specify a name for each of our mapping categories, and within each of those, we specify our key/value pairs that we can reference in our template. We reference these via the!FindInMap
function call (documentation coming soon).Resources
(1) This is a significant attribute in SAM templates, proceeding all the actual AWS resources to configure.Logical ID
(2) An alphanumeric name given to a resource. This must be unique for all resources in a template.Type
(3) The type of AWS resource this is. The format of this value isservice-provider::service-name::data-type-name
. For example,AWS::EC2::Instance
. Resource names are delimited by a double colon (::).Properties
(3) A set of key/value pair properties (or options) for the resource.DeletionPolicy
(3) AWS deletes resources upon CloudFormation stack update and deletion by default. But we can specify this attribute with a value of “Retain” when we want to retain a resource beyond the life of the stack.DependsOn
(3) If we want a resource to be created only after another resource is created, we can force this by specifying this attribute along with the logical resource name of the dependency. We can have a resource depend on one or more other resources.
For more details on CloudFormation templates, check out Tim Harkin’s blog post .