SAM template

Ok, let’s look at the SAM template that this Quick Start application created. Open up the api/template.yaml file in the Cloud9 environment.

Do you see a similarity with AWS CloudFormation? That is because AWS SAM is an extension of AWS CloudFormation. Any resource that you can create via AWS CloudFormation can be created with AWS SAM.

Line 2 - Transform: AWS::Serverless-2016-10-31. This instructs CloudFormation that this is a SAM template. This will “unwrap” the SAM template and transforms it to a full-fledged CloudFormation template.

Line 9 - Globals. You can provide common configurations using Globals. For instance, if you would like to set up the runtime as nodejs14.x and timeout as 30 seconds, you can do that for all the Lambda functions in the Globals section. In this example, the timeout is set at 3 seconds. This will apply to all functions within this template.

Line 15 - Type: AWS::Serverless::Function. This is a resource type that is understood by SAM. When “transformed”, it will create a Type: AWS::Lambda::Function. You can view a list of SAM resources here.

Line 20 - Events. This allows developers to specify the event sources that can invoke this function. In this sample, a REST API invokes this Lambda function.

SAM template