Project
sam init
Create a project interactively
sam init --runtime <runtime> --name <name>
--app-template <template> --no-interactive
Create a project without prompts
Zip package type; use --package-type Image with --base-image
for containers.
sam validate
Check the template is valid
sam validate --lint
Also lint with cfn-lint
sam list resources --stack-name <name>
Show resources and physical IDs
sam list endpoints --stack-name <name>
Show API and function endpoints
sam list stack-outputs --stack-name <name>
Show stack outputs
Local Testing
sam local invoke
Run the only function once
sam local invoke <FunctionId> --event
<file>
Run a function with an event file
sam local invoke --env-vars <file>
Set environment variables from JSON or .env
sam local invoke --debug-port <port>
Run with a debugger port exposed
sam local start-api
Serve the API on localhost:3000
sam local start-api --port <port>
Listen on another port
sam local start-api --warm-containers EAGER
Keep containers between requests
LAZY starts each container on first call.
sam local start-lambda
Emulate the Lambda endpoint locally
sam local generate-event
List services with sample events
sam local generate-event <service>
<event>
Print a sample event
Redirect to a file, then pass it with --event.
Deploy
sam deploy --guided
Answer prompts, save samconfig.toml
sam deploy
Deploy using saved config
sam deploy --stack-name <name> --resolve-s3
--capabilities CAPABILITY_IAM
Deploy with no prompts
CAPABILITY_NAMED_IAM if roles have custom names.
sam deploy --no-confirm-changeset
Skip the changeset prompt
sam deploy --no-execute-changeset
Create the changeset only
sam deploy --parameter-overrides
ParameterKey=<k>,ParameterValue=<v>
Set a template parameter
sam deploy --config-env <env>
Use a named samconfig.toml section
sam deploy --no-fail-on-empty-changeset
Exit 0 when nothing changed
By default an empty changeset exits non-zero.
sam deploy --profile <profile> --region
<region>
Pick credentials and region
sam deploy --output json
Machine-readable output for CI
Not compatible with --guided or --confirm-changeset.
Sync & Remote
sam sync --stack-name <name> --watch
Auto-sync code and infra changes
Dev stacks only: code updates go straight to Lambda via
service APIs.
sam sync --stack-name <name> --code
Push code changes once, skip CloudFormation
sam sync --stack-name <name> --code --resource-id
<FunctionId>
Sync a single resource
sam remote invoke <FunctionId> --stack-name
<name>
Invoke the deployed function
sam remote invoke <FunctionId> --stack-name
<name> --event '<json>'
Send an inline event
sam remote invoke <FunctionId> --stack-name
<name> --event-file <file>
Send an event from a file
Logs & Traces
sam logs --stack-name <name>
Fetch recent logs for the stack
Defaults to the last 10 minutes.
sam logs --stack-name <name> --tail
Follow logs live
sam logs -n <FunctionId> --stack-name
<name>
Logs for one function
sam logs --stack-name <name> --filter
"<pattern>"
Only matching log events
sam logs --stack-name <name> -s
'<time>' -e '<time>'
Logs in a time range
Accepts '10min ago' or '2018-01-01 10:10:10'.
sam logs --stack-name <name> --include-traces
Add X-Ray traces to the output
sam traces --tail
Follow X-Ray traces