Local testing with Amazon SAM CLI - 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).

Local testing with Amazon SAM CLI

The Amazon SAM CLI enables you to test serverless applications locally across different infrastructure as code (IaC) tools. This guide explains how to use the Amazon SAM CLI for local testing with various IaC frameworks.

Key benefits of using Amazon SAM CLI for local testing include:

  • Rapid development - Test code changes without deploying to Amazon

  • Cost efficiency - Develop and test without incurring Amazon charges

  • Offline capability - Work on your applications without an internet connection

  • Simplified debugging - Step through Lambda function code locally using a debugger

  • Realistic testing - Test your applications using local emulation of Amazon services

Test Amazon SAM applications locally

For information about testing applications defined using Amazon SAM templates, see Testing and debugging serverless applications in this guide.

Test Amazon CloudFormation templates locally

To use the Amazon SAM CLI's local testing capabilities with Amazon CloudFormation, add the Amazon SAM transform to your Amazon CloudFormation template. For more information, see Amazon SAM template anatomy for:

  • Adding Amazon SAM transform to Amazon CloudFormation templates

  • Understanding template compatibility

  • Exploring serverless resource syntax

Test Amazon CDK applications locally

You can use the Amazon SAM CLI to test Amazon CDK applications locally after you synthesize the Amazon CDK application to Amazon CloudFormation templates using the cdk synth command.

For more information, look at Locally test and build Amazon CDK applications with the Amazon SAM CLI in the Amazon CDK developer guide. This includes:

Test Terraform applications locally

The Amazon SAM CLI supports Terraform projects and Terraform Cloud. You can use it to perform local debugging and testing of: Lambda functions and layers and the Amazon API Gateway HTTP and REST APIs.

To set up your environment and learn about all available features, see Terraform Support in this guide. This includes: