AWS SAM (Serverless Application Model) is an extension of AWS CloudFormation used to build and deploy serverless applications easily.
Instead of writing many CloudFormation resources, you write a few simple SAM resources, and SAM generates the CloudFormation for you.
Think:
SAM = Simplified CloudFormation for Serverless
For the exam, remember this sequence:
Write template.yaml
↓
sam build
↓
sam deploy --guided (first time)
↓
CloudFormation creates AWS resourcesPurpose:
.aws-sam/ folderExample:
sam buildRemember:
Build prepares the application.
It does NOT deploy anything.
Purpose:
Example:
sam deploy --guidedFirst deployment:
sam deploy --guidedLater deployments:
sam deployRemember:
Deploy sends the application to AWS.
Purpose:
Run Lambda locally.
Example:
sam local invokeImportant:
It
Exam trick:
Local Invoke = Testing only
SAM templates are transformed into CloudFormation.
Deployment automatically creates:
No manual CloudFormation creation required.
Large SAM templates often repeat:
Instead of repeating them, use:
Globals:
Function:
Runtime: python3.12
Timeout: 30
MemorySize: 256Every Lambda automatically inherits these values.
Individual functions can still override them.
Example:
Globals:
Function:
Runtime: python3.12
Timeout: 30
Resources:
FunctionA:
Type: AWS::Serverless::Function
FunctionB:
Type: AWS::Serverless::FunctionBoth automatically use:
No repetition.
Exam tip:
Globals = Default settings for all functions.
Basic Lambda definition:
Resources:
HelloFunction:
Type: AWS::Serverless::FunctionSAM converts this into normal CloudFormation resources.
Example:
Events:
MyAPI:
Type: HttpApiThis small block automatically creates:
You do NOT manually create these resources.
Remember:
Events generate the event source automatically.
When using:
Type: HttpApiSAM creates:
It does NOT create:
Unless you define them separately.
HTTP API
REST API
If SAM Event Type is:
HttpApiSAM creates an HTTP API, not a REST API.
When deploying:
AWS::Serverless::Functionwith
Events:
Type: HttpApiSAM automatically creates:
You only write a few lines.
sam build deploys application.
❌ False
It only prepares artifacts.
sam local invoke deploys Lambda.
❌ False
Runs locally only.
Need to manually create CloudFormation stack.
❌ False
sam deploy creates the stack.
Globals cannot be overridden.
❌ False
Individual functions can override inherited values.
HttpApi creates REST API.
❌ False
Creates HTTP API Gateway (API Gateway V2).
.aws-samNot deployment
Automatically creates: