Amazon SAM CLI
Amazon Serverless Application Model Command Line Interface (Amazon SAM CLI) is a command-line tool for local development and testing of serverless applications. The Amazon SAM CLI allows you to build, transform, deploy, debug, package, initialize, and sync your serverless applications locally before deploying to the cloud.
Amazon SAM CLI works with serverless applications that are defined using different frameworks and infrastructure as code (IaC) tools, with varying levels of support:
-
Amazon SAM templates – Provides native support with the full feature set, including local testing, debugging, packaging, and deployment capabilities.
-
Amazon CDK applications – Supports local testing of Lambda functions after you synthesize the Amazon CDK application to Amazon CloudFormation templates using the cdk synth command.
-
Amazon CloudFormation templates – Offers direct compatibility because Amazon SAM extends Amazon CloudFormation, supporting serverless resources that are defined in standard Amazon CloudFormation templates.
-
Terraform applications – Provides limited support for building and local testing of Lambda functions. Requires you to generate Amazon SAM template artifacts that represent your Terraform-defined Lambda functions.
For the most comprehensive feature support and streamlined developer experience, we recommend using native Amazon SAM templates.
Topics
How Amazon SAM CLI commands are documented
Amazon SAM CLI commands are documented using the following format:
-
Prompt – The Linux prompt is documented by default and is displayed as (
$
). For commands that are Windows specific, (>
) is used as the prompt. Do not include the prompt when you type commands. -
Directory – When commands must be executed from a specific directory, the directory name is shown before the prompt symbol.
-
User input – Command text that you enter at the command line is formatted as
user input
. -
Replaceable text – Variable text, such as file names and parameters are formatted as
replaceable text
. In multiple-line commands or commands where specific keyboard input is required, keyboard input can also be shown as replaceable text. For example,ENTER
. -
Output – Output returned as a response to the command is formatted as
computer output
.
The following sam deploy
command and output is an example:
$
sam deploy --guided --template
Configuring SAM deploy ====================== Looking for config file [samconfig.toml] : Found Reading default arguments : Success Setting default arguments for 'sam deploy' ========================================= Stack Name [sam-app]:template.yaml
ENTER
AWS Region [us-west-2]:ENTER
#Shows you resources changes to be deployed and require a 'Y' to initiate deploy Confirm changes before deploy [y/N]:ENTER
#SAM needs permission to be able to create roles to connect to the resources in your template Allow SAM CLI IAM role creation [Y/n]:ENTER
#Preserves the state of previously provisioned resources when an operation fails Disable rollback [y/N]:ENTER
HelloWorldFunction may not have authorization defined, Is this okay? [y/N]:y
Save arguments to configuration file [Y/n]:ENTER
SAM configuration file [samconfig.toml]:ENTER
SAM configuration environment [default]:ENTER
-
sam deploy --guided --template template.yaml
is the command you enter at the command line. -
sam deploy --guided --template
should be provided as is. -
template.yaml
can be replaced with your specific file name. -
The output starts at
Configuring SAM deploy
. -
In the output,
ENTER
andy
indicate replaceable values that you provide.