AWS SAM CLI Terraform support - AWS Serverless Application Model

AWS SAM CLI Terraform support

This section covers using the AWS Serverless Application Model Command Line Interface (AWS SAM CLI) with your Terraform projects and Terraform Cloud.

To provide feedback and submit feature requests, create a GitHub Issue.

What is AWS SAM CLI support for Terraform?

Use the AWS Serverless Application Model Command Line Interface (AWS SAM CLI) with your Terraform projects or Terraform Cloud to perform local debugging and testing of:

  • AWS Lambda functions and layers.

  • Amazon API Gateway APIs.

For an introduction to Terraform, see What is Terraform? at the HashiCorp Terraform website.

To provide feedback and submit feature requests, create a GitHub Issue.

Note

As part of the parsing step of AWS SAM CLI's integration, AWS SAM CLI processes user commands generate project files and data. The command output should remain unchanged, but in certain environments, the environment or runner may inject additional logs or information in the output.

What is the AWS SAM CLI?

The AWS SAM CLI is a command line tool that you can use with AWS SAM templates and supported third-party integrations, such as Terraform, to build and run your serverless applications. For an introduction to the AWS SAM CLI, see What is the AWS SAM CLI?.

The AWS SAM CLI supports the following commands for Terraform:

  • sam local invoke – Initiate a one-time invocation of an AWS Lambda function resource locally. To learn more about this command, see Introduction to testing with sam local invoke.

  • sam local start-api – Run your Lambda resources locally and test through a local HTTP server host. This type of testing is helpful for Lambda functions that are invoked by an API Gateway endpoint. To learn more about this command, see Introduction to testing with sam local start-api.

  • sam local start-lambda – Start a local endpoint for your Lambda function in order to invoke your function locally using AWS Command Line Interface (AWS CLI) or SDKs. To learn more about this command, see Introduction to testing with sam local start-lambda.

How do I use the AWS SAM CLI with Terraform?

The core Terraform workflow consists of three stages: Write, Plan, and Apply. With AWS SAM CLI support for Terraform, you can take advantage of the AWS SAM CLI sam local set of commands while continuing to use your Terraform workflows to manage your applications on AWS. Generally, this means the following:

  • Write – Author your infrastructure as code using Terraform.

  • Test and debug – Use the AWS SAM CLI to locally test and debug your applications.

  • Plan – Preview changes before applying.

  • Apply – Provision your infrastructure.

For an example of using the AWS SAM CLI with Terraform, see Better together: AWS SAM CLI and HashiCorp Terraform at the AWS Compute Blog.

Next steps

To complete all prerequisites and set up Terraform, see Getting started with Terraform support for AWS SAM CLI.