SAM and SAR

Learn how to build serverless applications with SAM and SAR.

AWS SAM streamlines serverless application development using a simplified syntax, while SAR enables the discovery and deployment of reusable serverless applications and components through a managed repository.

Serverless Application Model

AWS Serverless Application Model (SAM) is an open-source framework for building serverless applications in a standardized way. It extends AWS CloudFormation to provide a simplified way of defining the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by a serverless application. In addition, it offers tools to locally test and debug applications before taking them to the cloud

Press + to interact

SAM has two major components: SAM template and SAM CLI.

SAM template

SAM template provides short-hand syntax to define the resources and event source mappings. It is built on top of CloudFormation.

We define the SAM template in template.yml file. It typically has the following sections:

  • Transform (required): This section is used to identify a CloudFormation template as a SAM template.

  • Globals (optional): This section defines the properties common to serverless tables, APIs, and functions. Properties or configuration settings defined in globals are inherited by multiple resources. It’s helpful in avoiding repetition in SAM templates.

  • Parameters (optional): This section is used to pass values to the template during stack creation or modification. We can use these values to customize the resources at runtime. It’s similar in functionality and structure to the Parameters section in CloudFormation. Parameters defined in the SAM template are overridden by the parameters described with the --parameter-overrides flag in the sam deploy command. We’ll learn more about sam deploy in the next task.

  • Resources (required): This section is the main part of the SAM template. Like the CloudFormation template, it defines the resources to be set up using the template. SAM template supports a variety of serverless resources offered by AWS. However, we can define other resources using the CloudFormation template within the SAM template. We’ll explore ...