| name | sam |
| description | Build, test, and deploy serverless applications with AWS SAM CLI (Lambda, API Gateway, DynamoDB, Step Functions). |
| metadata | {"openclaw":{"emoji":"🐿️","requires":{"bins":["sam"]}}} |
AWS SAM (Serverless Application Model)
Use this skill for serverless development: initializing SAM projects, building and packaging functions, local testing and debugging, deploying serverless stacks, and managing serverless APIs.
Prerequisites
- AWS SAM CLI installed (
brew install aws-sam-cli or pip)
- AWS CLI v2 configured with valid credentials
- Docker (for local invoke/testing)
- Language runtime matching your function (Python, Node.js, Go, Java, etc.)
Common Operations
Inspect and Status (Read-Only)
sam --version
sam validate
sam validate --lint
sam list resources --stack-name <stack-name>
sam list endpoints --stack-name <stack-name>
sam list stack-outputs --stack-name <stack-name>
Initialize Projects
sam init
sam init --runtime python3.12 --app-template hello-world --name my-app
sam init --location gh:aws/aws-sam-cli-app-templates
sam init --runtime nodejs20.x --package-type Zip --name my-node-app
sam init --runtime python3.12 --package-type Image --name my-container-app
Build
sam build
sam build --use-container
sam build <FunctionLogicalId>
sam build --manifest requirements.txt
sam build --parallel
Local Development and Testing
sam local invoke <FunctionLogicalId>
sam local invoke <FunctionLogicalId> --event events/event.json
sam local invoke <FunctionLogicalId> --env-vars env.json
sam local start-api
sam local start-api --port 3000
sam local start-lambda
sam local generate-event s3 put
sam local generate-event apigateway aws-proxy
sam local generate-event sqs receive-message
sam logs --name <FunctionLogicalId> --stack-name <stack-name> --tail
Deploy
⚠️ Cost note: SAM is free — costs come from the AWS resources deployed (Lambda, API Gateway, DynamoDB, etc.). Lambda free tier: 1M requests + 400K GB-seconds/month.
sam deploy --guided
sam deploy
sam deploy --parameter-overrides Environment=prod ApiKey=<key>
sam deploy --no-confirm-changeset
sam deploy --region <region>
sam deploy --s3-bucket <bucket-name> --s3-prefix <prefix>
sam package --output-template-file packaged.yaml --s3-bucket <bucket>
Sync (Accelerated Development)
sam sync --stack-name <stack-name>
sam sync --stack-name <stack-name> --watch
sam sync --stack-name <stack-name> --code
Delete / Destructive
🛑 DESTRUCTIVE — Always confirm with the user before executing any of these commands.
sam delete --stack-name <stack-name>
sam delete --stack-name <stack-name> --no-prompts
Safety Rules
- NEVER deploy without reviewing the changeset (avoid
--no-confirm-changeset in production).
- NEVER expose or log AWS credentials, API keys, or secret keys.
- ALWAYS use
sam validate --lint before deploying.
- ALWAYS test locally with
sam local invoke before deploying to production.
- WARN about Lambda cold starts and timeout configurations.
- WARN that
sam sync bypasses CloudFormation and is for development only.
Best Practices
- Use
sam build --use-container for consistent builds across environments.
- Define DLQs for async Lambda invocations.
- Use Layers for shared code and large dependencies.
- Set appropriate memory (128-10240 MB) and timeout (max 900s) for each function.
- Use
sam pipeline init and sam pipeline bootstrap for CI/CD pipelines.
Common Patterns
Pattern: Local API Development
sam build && sam local start-api --warm-containers EAGER
curl http://localhost:3000/hello
Pattern: Debug with Events
sam local generate-event s3 put --bucket my-bucket --key test.txt > events/s3-put.json
sam local invoke ProcessS3Event --event events/s3-put.json
Pattern: CI/CD Pipeline Deploy
sam build
sam deploy \
--no-confirm-changeset \
--no-fail-on-empty-changeset \
--stack-name my-app-prod \
--capabilities CAPABILITY_IAM \
--parameter-overrides Environment=prod
Troubleshooting
| Error | Cause | Fix |
|---|
Error: Template file not found | Not in project root | cd to directory with template.yaml |
Build Failed | Dependency installation error | Check runtime version; try --use-container |
Docker not found | Docker not running | Start Docker Desktop; needed for local invoke and --use-container |
CREATE_FAILED on deploy | Resource creation error | Check CloudFormation events; common: IAM permissions, naming conflicts |
No changes to deploy | Template unchanged | Use --no-fail-on-empty-changeset to suppress |
| Local invoke timeout | Function exceeds default 3s timeout | Increase Timeout in template.yaml |
Unable to import module | Missing dependency in package | Ensure requirements.txt / package.json is complete; rebuild |