Before we get going with writing our own SAM templates, it is important to understand a few SAM terms and terminologies. For starters; SAM is built on top of the standard CloudFormation service itself, so most of the SAM templates are nothing more than simplified CloudFormation templates that you can deploy just as you would deploy a standard CloudFormation stack! Even the concepts of resources, parameters, properties, and so on are all reused in SAM as well. The main difference however, is that simplified support for serverless AWS services namely API Gateway, Lambda functions, and DynamoDB makes these templates far easier to write and maintain than traditional CloudFormation ones.
Writing a SAM template starts off just as any other CloudFormation template does, with an AWSTemplateFormatVersion followed by a transform section that is specific to SAM. The transform section takes a value of AWS::Serverless-2016-10-31 as shown in the snippet below:
AWSTemplateFormatVersion: '2010-09-09' Transform: 'AWS::Serverless-2016-10-31'
After the transform section, you can have the resources section where you can define one or more serverless resource types. While writing this book, SAM supports three resource types namely:
- AWS::Serverless::Function
- AWS::Serverless::Api
- AWS::Serverless::SimpleTable