

# What is the AWS Serverless Application Model (AWS SAM)?
<a name="what-is-sam"></a>

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

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

1. AWS SAM Template - An extension of 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 AWS SAM project, that typically includes your AWS SAM template, application code, and other configuration files.

## When to use AWS SAM
<a name="when-to-use-sam"></a>

AWS SAM is an ideal IaC solution for scenarios where you want simplified serverless development with the full power of CloudFormation. For example, you can use SAM for:
+ **Serverless applications:** You can use SAM to quickly define AWS Lambda functions, Lambda durable functions, Amazon API Gateway APIs, Amazon DynamoDB tables, and other serverless resources with minimal code.
+ **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 AWS.
+ **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 AWS Management Console into infrastructure as code using SAM templates.

**Comparing AWS SAM with other IaC tools**
+ Use SAM instead of CloudFormation to simplify serverless resource definitions while maintaining template compatibility.
+ Use SAM instead of AWS CDK if you prefer a declarative approach to describing your infrastructure rather than a programmatic one.
+ Combine SAM with AWS CDK by using SAM CLI's local testing features to enhance your CDK applications.

## Key features
<a name="what-is-sam-feature"></a>

AWS 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 AWS SAM templates to define your serverless application infrastructure code. Deploy your templates directly to CloudFormation to provision your resources.

**Manage your serverless applications through their entire development lifecycle**  
Use the AWS SAM CLI to manage your serverless application through the authoring, building, deploying, testing, and monitoring phases of your development lifecycle. For more information, see [AWS SAM CLI](using-sam-cli.md).

**Quickly provision permissions between resources with AWS SAM connectors**  
Use AWS SAM connectors in your AWS SAM templates to define permissions between your AWS resources. AWS SAM transforms your code into the IAM permissions required to facilitate your intent. For more information, see [Managing resource permissions with AWS SAM connectors](managing-permissions-connectors.md).

**Continuously sync local changes to the cloud as you develop**  
Use the AWS 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 AWS Cloud](using-sam-cli-sync.md).

**Manage your Terraform serverless applications**  
Use the AWS SAM CLI to perform local debugging and testing of your Lambda functions and layers. For more information, see [AWS SAM CLI Terraform support](terraform-support.md).

## Related information
<a name="w2aab5c15"></a>
+ For information on how AWS SAM works, see [How AWS SAM works](what-is-sam-overview.md).
+ To start using AWS SAM, see [Getting started with AWS SAM](serverless-getting-started.md). 
+ For an overview on how you can use AWS SAM to create a serverless application, see [How to use AWS SAM](chapter-using-sam.md#chapter-using-sam.title).

# How AWS SAM works
<a name="what-is-sam-overview"></a>

When working with AWS SAM to create your serverless application, you will interact with the following components:

1. **[AWS SAM template](sam-specification.md)** – An important file that defines your AWS resources. This template includes the **AWS SAM template specification** – the open-source framework that comes with a simplified short-hand syntax you use to define the functions, events, APIs, configurations, and permissions of your serverless application. This file is located in the AWS SAM project, which is the application folder that gets created when you run the **sam init** command.

1. **[AWS SAM CLI](using-sam-cli.md)** – A command line tool that you can use with your AWS SAM project and supported third-party integrations to build and run your serverless applications. The AWS SAM CLI is the tool you use to run commands on your AWS SAM project and eventually turn it into your serverless application.

To express resources, event source mappings, and other properties that define your serverless application, you define resources and develop your application in the AWS SAM template and other files in your AWS SAM project. You use the AWS SAM CLI to run commands on your AWS SAM project, which is how you initialize, build, test, and deploy your serverless application.

**New to serverless?**  
We recommend you review [Serverless concepts for AWS Serverless Application Model](what-is-concepts.md).

## What is the AWS SAM template specification?
<a name="what-is-sam-template-spec"></a>

The AWS SAM template specification is an open-source framework that you can use to define and manage your serverless application infrastructure code. The AWS SAM template specification is:
+ **Built on AWS CloudFormation** – You use the CloudFormation syntax directly in your AWS SAM template, taking advantage of its extensive support of resource and property configurations. If you are already familiar with CloudFormation, you don't have to learn a new service to manage your application infrastructure code.
+ **An extension of CloudFormation** – AWS SAM offers its own unique syntax that focuses specifically on speeding up serverless development. You can use both the CloudFormation and AWS SAM syntax within the same template.
+ **An abstract, short-hand syntax** – Using the AWS SAM syntax, you can define your infrastructure quickly, in fewer lines of code, and with a lower chance of errors. Its syntax is especially curated to abstract away the complexity in defining your serverless application infrastructure.
+ **Transformational** – AWS SAM does the complex work of transforming your template into the code necessary to provision your infrastructure through CloudFormation.

## What is the AWS SAM project and AWS SAM template?
<a name="what-is-sam-template"></a>

The AWS SAM project includes the AWS SAM template which contains the AWS SAM template specification. This specification is the open-source framework that you use to define your serverless application infrastructure on AWS, with some additional components that make them easier to work with. In this sense, AWS SAM templates are an extension of CloudFormation templates.

Here’s an example of a basic serverless application. This application processes requests to get all items from a database through an HTTP request. It consists of the following parts:

1. A function that contains the logic to process the request.

1. An HTTP API to serve as communication between the client (requestor) and the application.

1. A database to store items.

1. Permissions for the application to run securely.

![\[Application architecture of simple serverless application.\]](http://docs.aws.amazon.com/serverless-application-model/latest/developerguide/images/what-is-sam-06.png)


This application's infrastructure code can be defined in the following AWS SAM template:

```
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Resources:
  getAllItemsFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: src/get-all-items.getAllItemsHandler
      Runtime: nodejs20.x
      Events:
        Api:
          Type: HttpApi
          Properties:
            Path: /
            Method: GET
    Connectors:
      MyConn:
        Properties:
          Destination:
            Id: SampleTable
          Permissions:
            - Read
  SampleTable:
    Type: AWS::Serverless::SimpleTable
```

In 23 lines of code, the following infrastructure is defined:
+ A function using the AWS Lambda service.
+ An HTTP API using the Amazon API Gateway service.
+ A database using the Amazon DynamoDB service.
+ The AWS Identity and Access Management (IAM) permissions necessary for these services to interact with one another.

To provision this infrastructure, the template is deployed to CloudFormation. During deployment, AWS SAM transforms the 23 lines of code into the CloudFormation syntax required to generate these resources in AWS. The transformed CloudFormation template contains over 200 lines of code\$1

### Transformed CloudFormation template
<a name="what-is-sam-template-example-cfn"></a>

```
{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "getAllItemsFunction": {
      "Type": "AWS::Lambda::Function",
      "Metadata": {
        "SamResourceId": "getAllItemsFunction"
      },
      "Properties": {
        "Code": {
          "S3Bucket": "amzn-s3-demo-source-bucket-1a4x26zbcdkqr",
          "S3Key": "what-is-app/a6f856abf1b2c4f7488c09b367540b5b"
        },
        "Handler": "src/get-all-items.getAllItemsHandler",
        "Role": {
          "Fn::GetAtt": [
            "getAllItemsFunctionRole",
            "Arn"
          ]
        },
        "Runtime": "nodejs12.x",
        "Tags": [
          {
            "Key": "lambda:createdBy",
            "Value": "SAM"
          }
        ]
      }
    },
    "getAllItemsFunctionRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",		 	 	 
          "Statement": [
            {
              "Action": [
                "sts:AssumeRole"
              ],
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "lambda.amazonaws.com"
                ]
              }
            }
          ]
        },
        "ManagedPolicyArns": [
          "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
        ],
        "Tags": [
          {
            "Key": "lambda:createdBy",
            "Value": "SAM"
          }
        ]
      }
    },
    "getAllItemsFunctionApiPermission": {
      "Type": "AWS::Lambda::Permission",
      "Properties": {
        "Action": "lambda:InvokeFunction",
        "FunctionName": {
          "Ref": "getAllItemsFunction"
        },
        "Principal": "apigateway.amazonaws.com",
        "SourceArn": {
          "Fn::Sub": [
            "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/",
            {
              "__ApiId__": {
                "Ref": "ServerlessHttpApi"
              },
              "__Stage__": "*"
            }
          ]
        }
      }
    },
    "ServerlessHttpApi": {
      "Type": "AWS::ApiGatewayV2::Api",
      "Properties": {
        "Body": {
          "info": {
            "version": "1.0",
            "title": {
              "Ref": "AWS::StackName"
            }
          },
          "paths": {
            "/": {
              "get": {
                "x-amazon-apigateway-integration": {
                  "httpMethod": "POST",
                  "type": "aws_proxy",
                  "uri": {
                    "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${getAllItemsFunction.Arn}/invocations"
                  },
                  "payloadFormatVersion": "2.0"
                },
                "responses": {}
              }
            }
          },
          "openapi": "3.0.1",
          "tags": [
            {
              "name": "httpapi:createdBy",
              "x-amazon-apigateway-tag-value": "SAM"
            }
          ]
        }
      }
    },
    "ServerlessHttpApiApiGatewayDefaultStage": {
      "Type": "AWS::ApiGatewayV2::Stage",
      "Properties": {
        "ApiId": {
          "Ref": "ServerlessHttpApi"
        },
        "StageName": "$default",
        "Tags": {
          "httpapi:createdBy": "SAM"
        },
        "AutoDeploy": true
      }
    },
    "SampleTable": {
      "Type": "AWS::DynamoDB::Table",
      "Metadata": {
        "SamResourceId": "SampleTable"
      },
      "Properties": {
        "AttributeDefinitions": [
          {
            "AttributeName": "id",
            "AttributeType": "S"
          }
        ],
        "KeySchema": [
          {
            "AttributeName": "id",
            "KeyType": "HASH"
          }
        ],
        "BillingMode": "PAY_PER_REQUEST"
      }
    },
    "getAllItemsFunctionMyConnPolicy": {
      "Type": "AWS::IAM::ManagedPolicy",
      "Metadata": {
        "aws:sam:connectors": {
          "getAllItemsFunctionMyConn": {
            "Source": {
              "Type": "AWS::Serverless::Function"
            },
            "Destination": {
              "Type": "AWS::Serverless::SimpleTable"
            }
          }
        }
      },
      "Properties": {
        "PolicyDocument": {
          "Version": "2012-10-17",		 	 	 
          "Statement": [
            {
              "Effect": "Allow",
              "Action": [
                "dynamodb:GetItem",
                "dynamodb:Query",
                "dynamodb:Scan",
                "dynamodb:BatchGetItem",
                "dynamodb:ConditionCheckItem",
                "dynamodb:PartiQLSelect"
              ],
              "Resource": [
                {
                  "Fn::GetAtt": [
                    "SampleTable",
                    "Arn"
                  ]
                },
                {
                  "Fn::Sub": [
                    "${DestinationArn}/index/*",
                    {
                      "DestinationArn": {
                        "Fn::GetAtt": [
                          "SampleTable",
                          "Arn"
                        ]
                      }
                    }
                  ]
                }
              ]
            }
          ]
        },
        "Roles": [
          {
            "Ref": "getAllItemsFunctionRole"
          }
        ]
      }
    }
  }
}
```

By using AWS SAM, you define 23 lines of infrastructure code. AWS SAM transforms your code into the 200\$1 lines of CloudFormation code necessary to provision your application.

## What is the AWS SAM CLI?
<a name="what-is-sam-cli"></a>

The AWS SAM CLI is a command line tool that you can use with AWS SAM templates and supported third-party integrations to build and run your serverless applications. Use the AWS SAM CLI to:
+ Quickly initialize a new application project.
+ Build your application for deployment.
+ Perform local debugging and testing.
+ Deploy your application.
+ Configure CI/CD deployment pipelines.
+ Monitor and troubleshoot your application in the cloud.
+ Sync local changes to the cloud as you develop.
+ And more\$1

The AWS SAM CLI is best utilized when used with AWS SAM and CloudFormation templates. It also works with third-party products such as Terraform.

### Initialize a new project
<a name="what-is-sam-cli-init"></a>

Select from starter templates or choose a custom template location to begin a new project.

Here, we use the **sam init** command to initialize a new application project. We select the **Hello World Example** project to start with. The AWS SAM CLI downloads a starter template and creates our project folder directory structure. 

![\[Using sam init to start a new application project with the AWS SAM CLI.\]](http://docs.aws.amazon.com/serverless-application-model/latest/developerguide/images/what-is-sam-01.gif)


For more details, see [Create your application in AWS SAM](using-sam-cli-init.md).

### Build your application for deployment
<a name="what-is-sam-cli-build"></a>

Package your function dependencies and organize your project code and folder structure to prepare for deployment.

Here, we use the **sam build** command to prepare our application for deployment. The AWS SAM CLI creates a `.aws-sam`directory and organizes our application dependencies and files there for deployment.

![\[Using sam build to prepare an application for deployment.\]](http://docs.aws.amazon.com/serverless-application-model/latest/developerguide/images/what-is-sam-02.gif)


For more details, see [Build your application](serverless-building.md).

### Perform local debugging and testing
<a name="what-is-sam-cli-local"></a>

On your local machine, simulate events, test APIs, invoke functions, and more to debug and test your application.

Here, we use the **sam local invoke** command to invoke our `HelloWorldFunction` locally. To accomplish this, the AWS SAM CLI creates a local container, builds our function, invokes it, and outputs the results. You can use an application like Docker to run containers on your machine.

![\[Using the AWS SAM CLI sam local invoke command to locally invoke a function.\]](http://docs.aws.amazon.com/serverless-application-model/latest/developerguide/images/what-is-sam-04.gif)


For more details, see [Test your application](serverless-test-and-debug.md) and [Debug your application](debug-application.md).

### Deploy your application
<a name="what-is-sam-cli-deploy"></a>

Configure your application's deployment settings and deploy to the AWS Cloud to provision your resources.

Here, we use the **sam deploy --guided** command to deploy our application through an interactive flow. The AWS SAM CLI guides us through configuring our application's deployment settings, transforms our template into CloudFormation, and deploys to CloudFormation to create our resources.

![\[Using the AWS SAM CLI sam deploy command to deploy an application to the AWS Cloud.\]](http://docs.aws.amazon.com/serverless-application-model/latest/developerguide/images/what-is-sam-03.gif)


For more details, see [Deploy your application and resources](serverless-deploying.md).

### Configure CI/CD deployment pipelines
<a name="what-is-sam-cli-cicd"></a>

Create secure *continuous integration and delivery (CI/CD)* pipelines, using a supported CI/CD system.

Here, we use the **sam pipeline init --bootstrap** command to configure a CI/CD deployment pipeline for our application. The AWS SAM CLI guides us through our options and generates the AWS resources and configuration file to use with our CI/CD system.

![\[Using the AWS SAM CLI sam pipeline init --bootstrap command to configure a CI/CD pipeline with our preferred CI/CD system.\]](http://docs.aws.amazon.com/serverless-application-model/latest/developerguide/images/what-is-sam-07.gif)


For more details, see [Deploy with CI/CD systems and pipelines](deploying-options.md#serverless-deploying-ci-cd).

### Monitor and troubleshoot your application in the cloud
<a name="what-is-sam-cli-monitor"></a>

View important information about your deployed resources, gather logs, and utilize built-in monitoring tools such as AWS X-Ray.

Here, we use the **sam list** command to view our deployed resources. We get our API endpoint and invoke it, which triggers our function. Then, we use **sam logs** to view our function's logs.

![\[Using the AWS SAM CLI sam list command to obtain our API endpoint. Then, sam logs is used to view our function's logs.\]](http://docs.aws.amazon.com/serverless-application-model/latest/developerguide/images/what-is-sam-08.gif)


For more details, see [Monitor your application](serverless-monitoring.md).

### Sync local changes to the cloud as you develop
<a name="what-is-sam-cli-sync"></a>

As you develop on your local machine, automatically sync changes to the cloud. Quickly see your changes and perform testing and validation in the cloud.

Here, we use the **sam sync --watch** command to have the AWS SAM CLI watch for local changes. We modify our `HelloWorldFunction` code and the AWS SAM CLI automatically detects the change and deploys our updates to the cloud. 

![\[Using the AWS SAM CLI sam sync command to sync local changes to the AWS Cloud.\]](http://docs.aws.amazon.com/serverless-application-model/latest/developerguide/images/what-is-sam-05.gif)


### Test supported resources in the cloud
<a name="what-is-sam-cli-remote-invoke"></a>

Invoke and pass events to supported resources in the cloud.

Here, we use the **sam remote invoke** command to test a deployed Lambda function in the cloud. We invoke our Lambda function and receive its logs and response. With our Lambda function configured to stream responses, the AWS SAM CLI streams its response back in real time.

![\[Using the AWS SAM CLI sam remote invoke command to test our deployed function in the AWS Cloud.\]](http://docs.aws.amazon.com/serverless-application-model/latest/developerguide/images/what-is-sam-09.gif)


## Learn more
<a name="what-is-sam-learn"></a>

To continue learning about AWS SAM, see the following resources:
+ **[The Complete AWS SAM Workshop](https://s12d.com/sam-ws-en-intro)** – A workshop designed to teach you many of the major features that AWS SAM provides.
+ **[ Sessions with SAM](https://www.youtube.com/playlist?list=PLJo-rJlep0ED198FJnTzhIB5Aut_1vDAd)** – Video series created by our AWS Serverless Developer Advocate team on using AWS SAM.
+ **[Serverless Land](https://serverlessland.com/)** – Site that brings together the latest information, blogs, videos, code, and learning resources for AWS serverless.

## Next steps
<a name="what-is-sam-next"></a>

If this is your first time using AWS SAM, see [Getting started with AWS SAM](serverless-getting-started.md).

# Serverless concepts for AWS Serverless Application Model
<a name="what-is-concepts"></a>

Learn about basic serverless concepts before using the AWS Serverless Application Model (AWS SAM).

## Serverless concepts
<a name="what-is-concepts-terms"></a>

**Event-driven architecture**  <a name="what-is-concepts-terms-eda"></a>
A serverless application consists of individual AWS services, such as AWS Lambda for compute and Amazon DynamoDB for database management, that each perform a specialized role. These services are then loosely integrated with each other through an event-driven architecture. To learn more about event-driven architecture, see [What is an Event-Driven Architecture?](https://aws.amazon.com/event-driven-architecture/). 

**Infrastructure as Code (IaC)**  <a name="what-is-concepts-terms-iac"></a>
Infrastructure as Code (IaC) is a way of treating infrastructure in the same way that developers treat code, applying the same rigor of application code development to infrastructure provisioning. You define your infrastructure in a template file, deploy it to AWS, and AWS creates the resources for you. With IaC, you define in code what you want AWS to provision. For a comparison of IaC tools available for AWS, see [Infrastructure as Code (IaC)](what-is-iac.md).

**Serverless technologies**  <a name="what-is-concepts-terms-serverless"></a>
With AWS serverless technologies, you can build and run applications without having to manage your own servers. All server management is done by AWS, providing many benefits such as automatic scaling and built-in high availability, letting you take your idea to production quickly. Using serverless technologies, you can focus on the core of your product without having to worry about managing and operating servers. To learn more about serverless, see the following:  
+ [Serverless on AWS](https://aws.amazon.com/serverless/)
+ [ Serverless Developer Guide](https://docs.aws.amazon.com/serverless/latest/devguide/serverless-preface.html) – Provides a conceptual overview of serverless development in the AWS Cloud.
For a basic introduction to the core AWS serverless services, see [Serverless 101: Understanding the serverless services](https://serverlessland.com/learn/serverless-101) at *Serverless Land*.

**Serverless Application**  <a name="what-is-concepts-terms-serverless"></a>
When you use AWS SAM, you manage related resources in an application, which consists of your AWS SAM project and template. All the resources in your application are defined or referred to in your AWS SAM template. When AWS SAM processes your template, it creates CloudFormation resources. In CloudFormation, resources are managed in a single unit called a stack, and all the resources in a stack are defined by the stack's CloudFormation template.

# Infrastructure as Code (IaC)
<a name="what-is-iac"></a>

With Infrastructure as Code (IaC), you can automate the deployment and management of your AWS resources, including serverless applications. IaC allows you to define your infrastructure using code, making it easier to version, share, and replicate your deployments. This approach helps you:
+ Speed up your development cycle
+ Simplify configuration management
+ Improve reliability and consistency of your deployments

## IaC tools for AWS serverless applications
<a name="iac-tools-aws"></a>

AWS offers several IaC tools to help you build, deploy, and manage your cloud resources. This section explains how AWS SAM fits within this ecosystem and works with other AWS IaC tools.

**AWS CloudFormation**  
Using [CloudFormation](https://aws.amazon.com/cloudformation/), you can model and provision your entire AWS infrastructure with YAML or JSON templates. CloudFormation handles resource creation, updates, and deletion automatically. When you deploy AWS SAM applications, CloudFormation processes the transformed templates to create and manage your resources.

**AWS Serverless Application Model (AWS SAM)**  
AWS SAM helps you build serverless applications with simplified syntax for defining serverless resources. You can use AWS SAM templates to provision Lambda functions, APIs, databases, and event sources using concise YAML syntax. AWS SAM transforms these templates into CloudFormation templates during deployment.  
While AWS SAM specializes in serverless applications, you can use any CloudFormation resource types in your AWS SAM templates. This gives you the flexibility to include non-serverless resources when needed.

**AWS Cloud Development Kit (AWS CDK)**  
With [AWS CDK](https://aws.amazon.com/cdk/), you can define your serverless infrastructure using familiar programming languages like TypeScript, Python, Java, C\$1/.Net, or Go. You can use programming constructs such as loops and conditions to define your infrastructure, and AWS CDK generates CloudFormation templates for deployment. You can use the AWS SAM CLI to locally test and debug applications created with AWS CDK. To learn more, see [Testing CDK applications locally](https://docs.aws.amazon.com/cdk/v2/guide/testing-locally.html).

## Comparing IaC tools for Serverless Applications
<a name="comparing-iac-tools"></a>

When choosing an IaC tool for your serverless applications, consider your team's preferences, project requirements, and existing workflows. The following table compares the key characteristics of AWS IaC tools for serverless development:


| **Tool** | **Primary use** | **Best for** | **Works with AWS SAM** | **When to choose** | 
| --- | --- | --- | --- | --- | 
| **CloudFormation** | Managing complex AWS infrastructure | Applications requiring detailed control of AWS resources | AWS SAM templates transform into CloudFormation templates during deployment | For fine-grained control over non-serverless resources | 
| **AWS SAM** | Serverless application development | Teams building serverless applications using Lambda | Native functionality | When focusing primarily on serverless architectures with Lambda functions, API Gateway APIs, and other serverless resources | 
| **AWS CDK** | Infrastructure definition using programming languages | Teams preferring typed languages and code-first approach | Generate AWS SAM templates and use AWS SAM CLI for testing | When you need programmatic infrastructure definition or complex resource configuration logic | 

**Note**  
While this guide focuses on AWS-native IaC tools, Terraform is another popular IaC solution that can be used to define serverless applications. The AWS SAM CLI supports local testing of Lambda functions defined in Terraform. For more information, see [AWS SAM CLI Terraform support](terraform-support.md).

## Learn more
<a name="iac-learn-more"></a>
+ To learn more about DevOps practices on AWS, see [Introduction to DevOps on AWS](https://docs.aws.amazon.com/whitepapers/latest/introduction-devops-aws/infrastructure-as-code.html)
+ For information about using Lambda with different IaC tools, see [Using Lambda with infrastructure as code (IaC)](https://docs.aws.amazon.com/lambda/latest/dg/foundation-iac.html)