AWS SAM (Serverless Application Model) – DVA-C02 Essentials


What is AWS SAM?

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


SAM Deployment Workflow

For the exam, remember this sequence:

Write template.yaml
        ↓
sam build
        ↓
sam deploy --guided (first time)
        ↓
CloudFormation creates AWS resources

sam build

Purpose:

Example:

sam build

Remember:

Build prepares the application.

It does NOT deploy anything.


sam deploy

Purpose:

Example:

sam deploy --guided

First deployment:

sam deploy --guided

Later deployments:

sam deploy

Remember:

Deploy sends the application to AWS.


sam local invoke

Purpose:

Run Lambda locally.

Example:

sam local invoke

Important:

It

Exam trick:

Local Invoke = Testing only


SAM uses CloudFormation

SAM templates are transformed into CloudFormation.

Deployment automatically creates:

No manual CloudFormation creation required.


Globals Section

Large SAM templates often repeat:

Instead of repeating them, use:

Globals:
  Function:
    Runtime: python3.12
    Timeout: 30
    MemorySize: 256

Every 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::Function

Both automatically use:

No repetition.

Exam tip:

Globals = Default settings for all functions.


AWS::Serverless::Function

Basic Lambda definition:

Resources:

  HelloFunction:
    Type: AWS::Serverless::Function

SAM converts this into normal CloudFormation resources.


Events Section

Example:

Events:

  MyAPI:
    Type: HttpApi

This small block automatically creates:

You do NOT manually create these resources.

Remember:

Events generate the event source automatically.


HttpApi Event

When using:

Type: HttpApi

SAM creates:

It does NOT create:

Unless you define them separately.


HTTP API vs REST API

HTTP API

REST API

If SAM Event Type is:

HttpApi

SAM creates an HTTP API, not a REST API.


Automatic Resources Created by SAM

When deploying:

AWS::Serverless::Function

with

Events:
    Type: HttpApi

SAM automatically creates:

You only write a few lines.


Common Exam Traps

Trap

sam build deploys application.

❌ False

It only prepares artifacts.


Trap

sam local invoke deploys Lambda.

❌ False

Runs locally only.


Trap

Need to manually create CloudFormation stack.

❌ False

sam deploy creates the stack.


Trap

Globals cannot be overridden.

❌ False

Individual functions can override inherited values.


Trap

HttpApi creates REST API.

❌ False

Creates HTTP API Gateway (API Gateway V2).


Quick Exam Memory Sheet

Build

Not deployment


Deploy


Local Invoke


Globals


HttpApi Event

Automatically creates:


10-Second Revision