AWS SAM CLI
The AWS Serverless Application Model (SAM) Command Line Interface (CLI) is an open-source tool that enables developers to build, test, debug, and deploy serverless applications defined by the AWS SAM specification. It provides a local Lambda-like execution environment and integrates with container tools like Docker and Finch for local development. Currently at version 1.158.0, it maintains a frequent release cadence with updates typically occurring weekly or bi-weekly.
Warnings
- breaking AWS SAM CLI discontinued official support for Python 3.7 as of October 24, 2023. If installed via pip, users on Python 3.7 will be affected. Upgrade your development environment to Python 3.8 or newer.
- gotcha Local development and testing features (e.g., `sam build`, `sam local invoke`, `sam local start-api`) require a containerization tool like Docker or Finch to be installed and running on your local machine.
- breaking Security vulnerabilities (CVE-2025-3047 and CVE-2025-3048) related to symlink handling during `sam build` with Docker were found. These could allow unauthorized access to host files.
- gotcha When using `sam sync` or `sam deploy` across multiple developer environments, explicitly naming resources (e.g., DynamoDB tables) in your `template.yaml` can lead to resource naming conflicts. CloudFormation generates unique names if not specified.
- gotcha The `.aws-sam/build` directory is an output directory for SAM CLI's build process. Manually modifying files within this directory is not recommended, as changes will be overwritten by subsequent `sam build` commands.
- deprecated The `sam package` command's functionality is now implicitly included within `sam deploy`. While `sam package` still works, it's generally recommended to use `sam deploy` directly, which handles both packaging and deployment.
Install
-
pip install aws-sam-cli -
brew tap aws/tap brew install aws-sam-cli
Imports
- AWS SAM CLI
This is a command-line interface tool and is not typically imported as a Python library in application code.
Quickstart
# Initialize a new serverless application (choose 'AWS Quick Start Templates', 'Python 3.x', 'Hello World Example') sam init --runtime python3.11 --app-template hello-world --name my-sam-app # Navigate into the project directory cd my-sam-app # Build your application (requires Docker or Finch for local container builds) sam build # Locally invoke the Lambda function with a sample event sam local invoke HelloWorldFunction --event events/event.json # Start a local API Gateway to test your API sam local start-api # Deploy your application to AWS Cloud (follow guided prompts) # Ensure AWS credentials are configured (e.g., via `aws configure` or environment variables) sam deploy --guided