Amazon SAM CLI Terraform support
This section covers using the Amazon Serverless Application Model Command Line Interface (Amazon SAM CLI) with your Terraform projects and Terraform Cloud.
To provide feedback and submit feature requests, create a GitHub
Issue
Topics
What is Amazon SAM CLI support for Terraform?
Use the Amazon Serverless Application Model Command Line Interface (Amazon SAM CLI) with your Terraform projects or Terraform Cloud to perform local debugging and testing of:
-
Amazon Lambda functions and layers.
-
Amazon API Gateway APIs.
For an introduction to Terraform, see What is Terraform?
To provide feedback and submit feature requests, create a GitHub
Issue
Note
As part of the parsing step of Amazon SAM CLI's integration, Amazon 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 Amazon SAM CLI?
The Amazon SAM CLI is a command line tool that you can use with Amazon SAM templates and supported third-party integrations, such as Terraform, to build and run your serverless applications. For an introduction to the Amazon SAM CLI, see What is the Amazon SAM CLI?.
The Amazon SAM CLI supports the following commands for Terraform:
-
sam local invoke
– Initiate a one-time invocation of an Amazon 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 Amazon Command Line Interface (Amazon CLI) or SDKs. To learn more about this command, see Introduction to testing with sam local start-lambda.
How do I use the Amazon SAM CLI with Terraform?
The core Terraform workflowsam local
set of commands while continuing to use your Terraform workflows to manage your applications on Amazon.
Generally, this means the following:
-
Write – Author your infrastructure as code using Terraform.
-
Test and debug – Use the Amazon SAM CLI to locally test and debug your applications.
-
Plan – Preview changes before applying.
-
Apply – Provision your infrastructure.
For an example of using the Amazon SAM CLI with Terraform, see
Better together: Amazon SAM CLI and HashiCorp Terraform
Next steps
To complete all prerequisites and set up Terraform, see Getting started with Terraform support for Amazon SAM CLI.