SAM
AWS Serverless Application Model (SAM) Overview
Overview
AWS SAM is an open-source framework that extends CloudFormation to simplify serverless application development. Here's a comprehensive breakdown:
Key Components
Template Specification
# Example SAM Template
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs18.x
Events:
ApiEvent:
Type: Api
Properties:
Path: /hello
Method: get
Resource Types
AWS::Serverless::Function
(Lambda)AWS::Serverless::Api
(API Gateway)AWS::Serverless::HttpApi
(HTTP API)AWS::Serverless::SimpleTable
(DynamoDB)AWS::Serverless::StateMachine
(Step Functions)AWS::Serverless::LayerVersion
(Lambda Layers)
Local Development Features
# Local testing commands
sam local start-api # Start local API Gateway
sam local invoke # Test Lambda functions
sam local start-lambda # Start local Lambda endpoint
Development Lifecycle
Advanced Features
Policy Templates
MyFunction:
Type: AWS::Serverless::Function
Properties:
Policies:
- S3ReadPolicy:
BucketName: !Ref MyBucket
- DynamoDBCrudPolicy:
TableName: !Ref MyTable
Layers Support
MyLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: ./layer
CompatibleRuntimes:
- nodejs18.x
Security Features
Built-in IAM role generation
Security policy templates
Integration with AWS security services
Development Tools
SAM CLI for local testing
AWS Toolkit integration (VS Code, JetBrains, etc.)
CloudFormation Designer compatibility
Best Practices
Use environment variables for configuration
Implement proper error handling
Set appropriate timeouts and memory
Use layers for shared code
Enable X-Ray tracing
Debugging Capabilities
# Debugging commands
sam logs -n MyFunction # View logs
sam trace # View traces
Deployment Options
# Deployment commands
sam deploy --guided # Interactive deployment
sam deploy --config-file # Use config file
Integration Points
CI/CD pipelines (AWS CodePipeline, GitHub Actions)
AWS X-Ray for tracing
CloudWatch for monitoring
AWS Step Functions for orchestration
Last updated
Was this helpful?