You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
The AWS Serverless Application Model (SAM) is an open-source framework for building serverless applications on AWS. It extends CloudFormation with simplified syntax for defining Lambda functions, API Gateway APIs, DynamoDB tables, and other serverless resources. SAM also includes a CLI for local development, testing, and deployment.
Building serverless applications with raw CloudFormation is verbose. A single Lambda function with an API Gateway trigger requires dozens of lines of CloudFormation. SAM reduces this to a few lines:
# You need to define:
# - AWS::Lambda::Function
# - AWS::Lambda::Permission
# - AWS::ApiGateway::RestApi
# - AWS::ApiGateway::Resource
# - AWS::ApiGateway::Method
# - AWS::ApiGateway::Deployment
# - AWS::ApiGateway::Stage
# - AWS::IAM::Role
# - AWS::IAM::Policy
# ... plus wiring them all together
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
HelloFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs20.x
Events:
HelloApi:
Type: Api
Properties:
Path: /hello
Method: get
SAM's Transform: AWS::Serverless-2016-10-31 directive tells CloudFormation to expand SAM resources into full CloudFormation resources at deployment time.
The SAM CLI is the command-line tool for building, testing, and deploying SAM applications:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.