What is the Amazon Serverless Application Model (Amazon SAM)? - Amazon Serverless Application Model
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

What is the Amazon Serverless Application Model (Amazon SAM)?

Amazon Serverless Application Model (Amazon SAM) is an open-source framework for building serverless applications using infrastructure as code (IaC). With Amazon SAM's shorthand syntax, developers declare Amazon CloudFormation resources and specialized serverless resources that are transformed to infrastructure during deployment. When working with Amazon SAM, you will interact with:

  1. Amazon SAM CLI - A command-line tool that helps you develop, locally test, and deploy your serverless applications.

  2. Amazon SAM Template - An extension of Amazon CloudFormation that provides simplified syntax for defining serverless resources.

When you use the sam init command, it creates a project directory, which we will refer to as the Amazon SAM project, that typically includes your Amazon SAM template, application code, and other configuration files.

When to use Amazon SAM

Amazon SAM is an ideal IaC solution for scenarios where you want simplified serverless development with the full power of Amazon CloudFormation. For example, you can use SAM for:

  • Serverless applications: You can use SAM to quickly define Amazon Lambda functions, Amazon API Gateway APIs, Amazon DynamoDB tables, and other serverless resources with minimal code.

  • Amazon CloudFormation enhancement: You can combine SAM with existing CloudFormation templates to add serverless components to traditional infrastructure. SAM resources work alongside standard CloudFormation resources in the same template.

  • Local development and testing: You can use the SAM CLI to test Lambda functions locally, simulate API Gateway endpoints, and debug serverless applications on your development machine before deploying to Amazon.

  • CI/CD for serverless: You can build deployment pipelines using SAM templates that automatically generate the CloudFormation infrastructure needed for staging and production environments.

  • Migration from console-created resources: You can convert Lambda functions and API Gateway resources created in the Amazon Management Console into infrastructure as code using SAM templates.

Comparing Amazon SAM with other IaC tools

  • Use SAM instead of CloudFormation to simplify serverless resource definitions while maintaining template compatibility.

  • Use SAM instead of Amazon CDK if you prefer a declarative approach to describing your infrastructure rather than a programmatic one.

  • Combine SAM with Amazon CDK by using SAM CLI's local testing features to enhance your CDK applications.

Key features

Amazon SAM offers a variety of benefits that improve the developer experience by allowing you to:

Define your application infrastructure code quickly, using less code

Author Amazon SAM templates to define your serverless application infrastructure code. Deploy your templates directly to Amazon CloudFormation to provision your resources.

Manage your serverless applications through their entire development lifecycle

Use the Amazon SAM CLI to manage your serverless application through the authoring, building, deploying, testing, and monitoring phases of your development lifecycle. For more information, see Amazon SAM CLI.

Quickly provision permissions between resources with Amazon SAM connectors

Use Amazon SAM connectors in your Amazon SAM templates to define permissions between your Amazon resources. Amazon SAM transforms your code into the IAM permissions required to facilitate your intent. For more information, see Managing resource permissions with Amazon SAM connectors.

Continuously sync local changes to the cloud as you develop

Use the Amazon SAM CLI sam sync command to automatically sync local changes to the cloud, speeding up your development and cloud testing workflows. For more information, see Introduction to using sam sync to sync to Amazon Web Services Cloud.

Manage your Terraform serverless applications

Use the Amazon SAM CLI to perform local debugging and testing of your Lambda functions and layers. For more information, see Amazon SAM CLI Terraform support.

Related information