2.1.3. AWS Serverless Application Model (SAM)
First Principle: AWS Serverless Application Model (SAM) simplifies the definition and deployment of serverless applications by providing a concise syntax for common serverless resources.
Loading diagram...
SAM defines this entire architecture in a single template file ā API Gateway, Lambda functions, DynamoDB table, and S3 bucket with their permissions and event mappings.
AWS Serverless Application Model (SAM) is an open-source framework that extends AWS CloudFormation to provide a simplified way of defining serverless applications. It offers a shorthand syntax for declaring serverless resources like Lambda functions, API Gateway APIs, and DynamoDB tables.
- Simplified Syntax: Express common serverless resources with fewer lines of code than raw CloudFormation.
- SAM CLI: Provides local testing capabilities (
sam local invoke,sam local start-api), dependency bundling, and deployment commands (sam deploy). - CloudFormation Transformation: SAM templates are transformed by AWS into standard CloudFormation templates before deployment, leveraging CloudFormation's robust deployment capabilities.
- Developer-Centric: Designed to accelerate the developer experience for serverless applications.
Scenario: You're building a new serverless application with several Lambda functions and an API Gateway endpoint. You want a simplified way to define these resources and deploy your application, avoiding verbose CloudFormation syntax. You also need to test your Lambda functions locally.
ā ļø Exam Trap: SAM is a superset of CloudFormation ā every SAM template is valid CloudFormation, but not vice versa. SAM simplifies serverless resources but uses CloudFormation for deployment. sam deploy runs aws cloudformation deploy under the hood.
