Skip to main content
AWS SAM Architecture

Module Overview

Estimated Time: 3-4 hours | Difficulty: Intermediate | Prerequisites: Lambda, CloudFormation basics
AWS SAM (Serverless Application Model) is an open-source framework for building serverless applications. It extends CloudFormation with simplified syntax and provides a CLI for local development and deployment. Think of SAM as CloudFormation’s serverless-specific dialect — you write 20 lines of SAM and it expands into 200 lines of CloudFormation behind the scenes. The trade-off is less flexibility (you cannot control every CloudFormation property), but for 90% of serverless use cases, SAM’s defaults are exactly what a senior engineer would configure anyway. What You’ll Learn:
  • SAM template structure and syntax
  • Local development and testing
  • Deployment and CI/CD integration
  • Common serverless patterns
  • SAM CLI commands and workflows

Why SAM?

Simplified Syntax

Write less CloudFormation—SAM handles the boilerplate

Local Testing

Test Lambda functions and APIs locally before deployment

Best Practices Built-in

Automatic IAM policies, API Gateway configuration, and more

Portable

Deploy anywhere—SAM transforms to standard CloudFormation

SAM Template Structure


SAM Resource Types

AWS::Serverless::Function

AWS::Serverless::Api

AWS::Serverless::HttpApi

Other SAM Resources


SAM CLI Commands

Local Development

Deployment

Debugging and Monitoring


Project Structure

samconfig.toml


Policy Templates

SAM provides policy templates for common use cases:

Testing

Unit Tests

Integration Tests


CI/CD Integration

GitHub Actions


Best Practices

Use Globals

Define common settings in Globals section to reduce repetition

Layer Dependencies

Put shared dependencies in Lambda Layers for faster deployments

Use Policy Templates

SAM policy templates follow least privilege by default

Local Testing

Always test locally before deploying—it’s faster and free

🎯 Interview Questions

SAM:
  • Best for pure serverless applications (Lambda + API Gateway + DynamoDB)
  • Simplified syntax, built-in best practices, least boilerplate
  • Excellent local testing with sam local
  • Limitation: Awkward when you mix serverless with traditional resources (VPCs, ECS)
CDK:
  • Programmatic (TypeScript, Python) — real programming constructs, loops, conditionals
  • Better for complex infrastructure that mixes serverless and non-serverless
  • Steeper learning curve but more flexible
  • A senior engineer would say: “Use CDK when your SAM template starts needing CloudFormation escape hatches everywhere”
Terraform:
  • Multi-cloud support — the only real option if you deploy to AWS AND GCP/Azure
  • Established ecosystem with mature state management
  • More verbose for serverless, but consistent across all infrastructure
  • Common mistake: Choosing Terraform for a pure-serverless AWS project just because your team knows it — SAM or CDK will be 3x less code
SAM CLI:
  1. Builds Docker container matching Lambda runtime
  2. Mounts your code into container
  3. Invokes handler with event
  4. Returns response
Supports debugging with port attachment.

Next Module

AWS GuardDuty

Intelligent threat detection for your AWS environment