

# Local testing with Amazon SAM CLI
<a name="using-sam-cli-local-testing"></a>

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
<a name="using-sam-cli-local-testing-sam"></a>

For information about testing applications defined using Amazon SAM templates, see [Testing and debugging serverless applications](serverless-test-and-debug.md) in this guide.

## Test Amazon CloudFormation templates locally
<a name="using-sam-cli-local-testing-cfn"></a>

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](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy.html) for:
+ Adding Amazon SAM transform to Amazon CloudFormation templates
+ Understanding template compatibility
+ Exploring serverless resource syntax

## Test Amazon CDK applications locally
<a name="using-sam-cli-local-testing-cdk"></a>

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](https://docs.aws.amazon.com/cdk/v2/guide/testing-locally.html) in the Amazon CDK developer guide. This includes:
+ [Getting started with locally testing](https://docs.aws.amazon.com/cdk/v2/guide/testing-locally.html#testing-locally-getting-started)
+ [Local testing Amazon CDK applications with Amazon SAM](https://docs.aws.amazon.com/cdk/v2/guide/testing-locally.html#testing-locally-sam)

## Test Terraform applications locally
<a name="using-sam-cli-local-testing-terraform"></a>

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](terraform-support.md) in this guide. This includes:
+ [Getting started with Terraform support for Amazon SAM CLI](gs-terraform-support.md)
+ [Using the Amazon SAM CLI with Terraform for local debugging and testing](using-samcli-terraform.md)