0Pricing
Serverless Backend with AWS Lambda & API Gateway · Lesson

Introduction to AWS SAM

Discover the benefits of AWS SAM for defining serverless resources and simplifying deployments compared to raw CloudFormation.

Introduction to AWS SAM is a free Serverless Backend with AWS Lambda & API Gateway lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Serverless Backend with AWS Lambda & API Gateway learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Welcome to AWS SAM!

Hello! Today we'll explore AWS SAM, the Serverless Application Model. It's an open-source framework designed to help you build serverless applications on AWS more efficiently.

Think of SAM as a powerful extension to AWS CloudFormation, specifically tailored for serverless resources.

CloudFormation's Verbosity

AWS CloudFormation is a robust service for defining infrastructure as code. However, building serverless applications directly with CloudFormation can be quite verbose.

  • A simple AWS Lambda function often requires defining the Lambda resource itself, an IAM role with permissions, and possibly an API Gateway endpoint.
  • This can lead to many lines of configuration for even basic setups.

SAM to the Rescue!

AWS SAM aims to simplify this complexity. It provides a shorthand syntax to define common serverless resources.

Instead of defining multiple CloudFormation resources for a single serverless component, SAM lets you define it with just one simplified resource type.

Key Benefits of Using SAM

Using AWS SAM brings several advantages to your serverless development workflow:

  • Reduced Boilerplate: Define serverless functions, APIs, and databases with fewer lines of code.
  • Local Testing: Test your Lambda functions and API Gateway locally before deploying to AWS.
  • Simplified Deployments: The SAM CLI handles packaging, uploading, and deploying your application seamlessly.
  • CloudFormation Power: It's built on CloudFormation, so you still get its reliability and features.

SAM Template Basics

Your serverless application's infrastructure is defined in a SAM template, which is typically a YAML or JSON file. The most crucial part that tells CloudFormation to use SAM's simplified syntax is the Transform section.

This Transform line instructs CloudFormation to expand SAM's shorthand into full CloudFormation resources before deployment.

Your First SAM Template

Let's look at a very basic SAM template. This YAML defines a simple 'Hello World' Lambda function. Notice how concise it is compared to what raw CloudFormation would require for the same setup!

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: A simple 'Hello World' SAM app.

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: app.lambda_handler
      Runtime: python3.9
      CodeUri: ./
      MemorySize: 128
      Timeout: 30

Deconstructing the Template

Let's break down that template:

  • Transform: AWS::Serverless-2016-10-31: This tells CloudFormation to process the SAM specific syntax.
  • Type: AWS::Serverless::Function: This is a SAM resource type. It automatically creates the Lambda function, an execution IAM role, and necessary permissions.
  • Handler, Runtime, CodeUri: These are standard AWS Lambda properties, specifying where your code is, its language, and the entry point.

SAM CLI - Your Serverless Sidekick

While SAM templates define your resources, the SAM Command Line Interface (CLI) is your primary tool for interacting with your serverless application.

The SAM CLI allows you to:

  • Build your application (e.g., package dependencies).
  • Test your Lambda functions locally.
  • Deploy your application to AWS.

The SAM Workflow (High-Level)

A typical SAM development workflow involves these high-level steps:

  1. Write your Lambda function code (e.g., Python, Node.js).
  2. Define your application's resources in a SAM template (YAML/JSON).
  3. Use sam build to prepare your application for deployment.
  4. Use sam deploy to push your application to AWS.

The SAM CLI handles all the underlying CloudFormation magic!

Quick Check on SAM

Based on what we've learned, what is the primary purpose of AWS SAM?

Recap & Next Steps

You've just been introduced to AWS SAM! We learned that SAM simplifies serverless development by providing a concise way to define resources, building on top of CloudFormation.

You also saw a basic SAM template and learned about the powerful SAM CLI.

Next, we'll dive deeper into defining various serverless resources within your SAM templates, including functions, APIs, and databases!

Frequently asked questions

Is the “Introduction to AWS SAM” lesson free?

Yes — the full text of “Introduction to AWS SAM” is free to read here on the web, and the Serverless Backend with AWS Lambda & API Gateway course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Serverless Backend with AWS Lambda & API Gateway course, upgrade to CoddyKit PRO.

What will I learn in “Introduction to AWS SAM”?

Discover the benefits of AWS SAM for defining serverless resources and simplifying deployments compared to raw CloudFormation. You practise Serverless Backend with AWS Lambda & API Gateway with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Serverless Backend with AWS Lambda & API Gateway?

No prior experience is required. Serverless Backend with AWS Lambda & API Gateway on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Introduction to AWS SAM” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Serverless Backend with AWS Lambda & API Gateway lesson?

Yes. Every Serverless Backend with AWS Lambda & API Gateway lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Introduction to AWS SAM
  2. Defining Serverless Resources
  3. Deploying SAM Applications
  4. Local Testing and Debugging with SAM CLI
← Back to Serverless Backend with AWS Lambda & API Gateway