---
title: "Deploying Serverless Applications with AWS SAM"
lang: "en"
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/post/deploying-serverless-applications-with-aws-sam
---

![Blog post image for Deploying Serverless Applications with AWS SAM - AWS SAM (Serverless Application Model) extends AWS CloudFormation with a simpler syntax for defining and deploying serverless functions, APIs, and event sources. This post covers SAM templates, local testing with the SAM CLI, and best practices for building serverless applications on AWS.](/_astro/hero.CdyEyleP_Z1IXAtr.webp)

[Home](/)›[Blog](/blog)›[All Categories](/blog/categories)›[AWS](/blog/categories/aws)

Blog

[Prev in AWSCloud Native Infrastructure on AWS](/blog/post/cloud-native-infrastructure-on-aws)[Next in AWSHow to Avoid Common Cloud Services Mistakes](/blog/post/how-to-avoid-common-cloud-services-mistakes)

[AWS](/blog/categories/aws)[Serverless](/blog/categories/serverless)[DevOps](/blog/categories/devops)[Infrastructure as Code](/blog/categories/infrastructure-as-code)[Application Deployment](/blog/categories/application-deployment)

# Deploying Serverless Applications with AWS SAM

[Mohammad Abu Mattar](/authors/mohammad-abu-mattar)Published: 22 May 202302 Mins read07 Mins listen

[Markdown for AI(opens in a new tab)](/post/deploying-serverless-applications-with-aws-sam/index.md "Open the plain-Markdown version of this page, for pasting into an AI tool")

TL;DR

AWS SAM (Serverless Application Model) extends AWS CloudFormation with a simpler syntax for defining and deploying serverless functions, APIs, and event sources. This post covers SAM templates, local testing with the SAM CLI, and best practices for building serverless applications on AWS.

Series

[Infrastructure as Code Mastery](/series/infrastructure-as-code-mastery)5/8

[PreviousAWS CloudFormation for Infrastructure as Code (IaC)](/blog/post/aws-cloudformation-for-infrastructure-as-code-iac)[NextOrchestrating Infrastructure with Terraform](/blog/post/orchestrating-infrastructure-with-terraform)

All posts in this series (8)

Blog8

1.  [Infrastructure Automation on AWS: CloudFormation, SAM, and Terraform for IaC](/blog/post/infrastructure-automation-on-aws-cloudformation-sam-and-terraform-for-iac)
2.  [Understanding Infrastructure as Code (IaC)](/blog/post/understanding-infrastructure-as-code-iac)
3.  [Cloud Native Infrastructure on AWS](/blog/post/cloud-native-infrastructure-on-aws)
4.  [AWS CloudFormation for Infrastructure as Code (IaC)](/blog/post/aws-cloudformation-for-infrastructure-as-code-iac)
5.  [Deploying Serverless Applications with AWS SAMYou are here](/blog/post/deploying-serverless-applications-with-aws-sam)
6.  [Orchestrating Infrastructure with Terraform](/blog/post/orchestrating-infrastructure-with-terraform)
7.  [Best Practices for Infrastructure Automation in a Cloud Native AWS Environment](/blog/post/best-practices-for-infrastructure-automation-in-a-cloud-native-aws-environment)
8.  [Navigating the Future of Cloud with Multi-Cloud IaC: Pulumi and Crossplane](/blog/post/multi-cloud-iac-pulumi-crossplane-future-cloud)

### Deploying Serverless Applications with AWS SAM

Contents

[Introduction](#introduction)[Understanding AWS SAM](#understanding-aws-sam)[How serverless works](#how-serverless-works)[Meet AWS SAM](#meet-aws-sam)[SAM templates](#sam-templates)[Structure and syntax](#structure-and-syntax)[Defining serverless resources](#defining-serverless-resources)[Simpler deployment](#simpler-deployment)[Working with SAM](#working-with-sam)[Local development and testing](#local-development-and-testing)[Lambda Layers and packaging](#lambda-layers-and-packaging)[Integration with AWS services](#integration-with-aws-services)[Best practices for SAM in application deployment](#best-practices-for-sam-in-application-deployment)[Modularity and reusability](#modularity-and-reusability)[Security and access control](#security-and-access-control)[Monitoring and observability](#monitoring-and-observability)[Conclusion](#conclusion)[References](#references)

## [Introduction](#introduction)

AWS SAM (Serverless Application Model) extends AWS CloudFormation with a simpler syntax for defining and deploying serverless applications. SAM templates let you define and deploy your serverless functions, APIs, and event sources without managing CloudFormation’s full complexity directly.

## [Understanding AWS SAM](#understanding-aws-sam)

### [How serverless works](#how-serverless-works)

Serverless architecture lets you focus on writing code without worrying about server management or infrastructure provisioning. It’s built on AWS Lambda, which supports scalable, event-driven applications.

### [Meet AWS SAM](#meet-aws-sam)

AWS Serverless Application Model (SAM) is an open-source framework that extends AWS CloudFormation. It provides a simplified syntax and set of tools specifically designed for building and deploying serverless applications.

## [SAM templates](#sam-templates)

### [Structure and syntax](#structure-and-syntax)

SAM templates use YAML or JSON to define your serverless application’s resources, such as functions, APIs, and event sources. The template structure is concise, which makes it easy to read and maintain.

### [Defining serverless resources](#defining-serverless-resources)

With SAM templates, you can declare your AWS Lambda functions, their event sources, and associated permissions. You can also define REST APIs using Amazon API Gateway and configure their endpoints and methods.

### [Simpler deployment](#simpler-deployment)

SAM templates simplify the deployment process by automating the creation of necessary resources and handling dependencies. You can deploy your application using the SAM CLI (Command Line Interface) or integrate it into your CI/CD pipelines.

## [Working with SAM](#working-with-sam)

### [Local development and testing](#local-development-and-testing)

SAM CLI provides a local development environment where you can test and debug your serverless applications before deploying them to the cloud. You can iterate and debug faster because you are not waiting on a deploy to see the result.

### [Lambda Layers and packaging](#lambda-layers-and-packaging)

SAM lets you use Lambda Layers to share common code and dependencies across multiple functions. It also simplifies the packaging process by automatically bundling your code and dependencies into deployment packages.

### [Integration with AWS services](#integration-with-aws-services)

SAM integrates with other AWS services, such as Amazon DynamoDB, Amazon S3, and Amazon SQS, letting you incorporate them into your serverless applications with less configuration. The template wires up the permissions and event mappings between them for you.

## [Best practices for SAM in application deployment](#best-practices-for-sam-in-application-deployment)

### [Modularity and reusability](#modularity-and-reusability)

Design your SAM templates with modularity in mind, creating reusable components and Lambda functions that can be shared across multiple applications. That keeps things consistent and cuts duplicated code.

### [Security and access control](#security-and-access-control)

Implement secure practices by configuring IAM (Identity and Access Management) roles and policies for your serverless functions and APIs. Limit permissions to only what is required and implement encryption for sensitive data.

### [Monitoring and observability](#monitoring-and-observability)

Use AWS CloudWatch to see how your serverless applications perform and behave. Configure logging and monitoring metrics for visibility so you can troubleshoot issues efficiently.

## [Conclusion](#conclusion)

AWS SAM simplifies the deployment of serverless applications. With SAM templates, you can define functions, APIs, and event sources without managing every CloudFormation detail by hand.

## [References](#references)

1.  AWS Serverless Application Model (SAM) Developer Guide, [https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html)
2.  AWS SAM CLI Command Reference, [https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference.html](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference.html)
3.  AWS Lambda Developer Guide, [https://docs.aws.amazon.com/lambda/latest/dg/welcome.html](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)
4.  Amazon API Gateway Developer Guide, [https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html)
5.  What is Serverless Computing? - AWS, [https://aws.amazon.com/serverless/](https://aws.amazon.com/serverless/)
6.  AWS CloudFormation User Guide, [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)
7.  AWS SAM Templates - AWS Documentation, [https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy.html](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy.html)
8.  Using Lambda Layers - AWS Lambda, [https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html)
9.  Security Best Practices for AWS Lambda, [https://docs.aws.amazon.com/lambda/latest/dg/best-practices-security.html](https://docs.aws.amazon.com/lambda/latest/dg/best-practices-security.html)
10.  Monitoring and Observability for Serverless Applications on AWS, [https://aws.amazon.com/serverless/monitoring-and-observability/](https://aws.amazon.com/serverless/monitoring-and-observability/)
11.  AWS SAM GitHub Repository (for examples and issues.), [https://github.com/aws/aws-sam-cli](https://github.com/aws/aws-sam-cli)
12.  AWS CloudWatch User Guide, [https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)

Was this useful?

## Tags

[#AWS SAM](/blog/tags/aws-sam)[#Serverless Framework](/blog/tags/serverless-framework)[#AWS Lambda](/blog/tags/aws-lambda)[#API Gateway](/blog/tags/api-gateway)[#IaC for Serverless](/blog/tags/iac-for-serverless)[#CloudFormation](/blog/tags/cloudformation)[#Serverless Deployment](/blog/tags/serverless-deployment)[#DevOps Practices](/blog/tags/devops-practices)

## Share

[Facebook](https://facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fdeploying-serverless-applications-with-aws-sam "Share on Facebook")[Twitter](https://twitter.com/intent/tweet/?text=Deploying%20Serverless%20Applications%20with%20AWS%20SAM&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fdeploying-serverless-applications-with-aws-sam "Share on Twitter")[LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fdeploying-serverless-applications-with-aws-sam&title=Deploying%20Serverless%20Applications%20with%20AWS%20SAM&summary=AWS%20SAM%20\(Serverless%20Application%20Model\)%20extends%20AWS%20CloudFormation%20with%20a%20simpler%20syntax%20for%20defining%20and%20deploying%20serverless%20functions%2C%20APIs%2C%20and%20event%20sources.%20This%20post%20covers%20SAM%20templates%2C%20local%20testing%20with%20the%20SAM%20CLI%2C%20and%20best%20practices%20for%20building%20serverless%20applications%20on%20AWS.&source=https://mkabumattar.com "Share on LinkedIn")[WhatsApp](https://wa.me/?text=Deploying%20Serverless%20Applications%20with%20AWS%20SAM%20https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fdeploying-serverless-applications-with-aws-sam "Share on WhatsApp")[Telegram](https://t.me/share/url?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fdeploying-serverless-applications-with-aws-sam&text=Deploying%20Serverless%20Applications%20with%20AWS%20SAM "Share on Telegram")[Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fdeploying-serverless-applications-with-aws-sam&title=Deploying%20Serverless%20Applications%20with%20AWS%20SAM "Share on Reddit")[Hacker News](http://news.ycombinator.com/submitlink?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fdeploying-serverless-applications-with-aws-sam&t=Deploying%20Serverless%20Applications%20with%20AWS%20SAM "Share on Hacker News")[Pinterest](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fdeploying-serverless-applications-with-aws-sam&media=&description=AWS%20SAM%20\(Serverless%20Application%20Model\)%20extends%20AWS%20CloudFormation%20with%20a%20simpler%20syntax%20for%20defining%20and%20deploying%20serverless%20functions%2C%20APIs%2C%20and%20event%20sources.%20This%20post%20covers%20SAM%20templates%2C%20local%20testing%20with%20the%20SAM%20CLI%2C%20and%20best%20practices%20for%20building%20serverless%20applications%20on%20AWS. "Share on Pinterest")[Email](<mailto:?subject=Deploying%20Serverless%20Applications%20with%20AWS%20SAM&body=Check out this article: https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fdeploying-serverless-applications-with-aws-sam>)

## Comments

## You might also enjoy

More posts on similar topics

[![Cloud Native Infrastructure on AWS](/_astro/hero.CwVzviwB_4akIX.webp)](/blog/post/cloud-native-infrastructure-on-aws)

## [Cloud Native Infrastructure on AWS](/blog/post/cloud-native-infrastructure-on-aws)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [Cloud Native](/blog/categories/cloud-native)
-   [Serverless](/blog/categories/serverless)
-   [DevOps](/blog/categories/devops)
-   [Infrastructure as Code](/blog/categories/infrastructure-as-code)

Introduction Cloud native infrastructure lets developers design and deploy applications built specifically for the cloud, rather than adapted to it. Using AWS services well, it enables application

[#Cloud Native Architecture](/blog/tags/cloud-native-architecture)[#AWS Services](/blog/tags/aws-services)[#AWS Lambda](/blog/tags/aws-lambda)+10 tags

[read more](/blog/post/cloud-native-infrastructure-on-aws)

[![Infrastructure Automation on AWS: CloudFormation, SAM, and Terraform for IaC](/_astro/hero.BsNJX0oJ_LxOfi.webp)](/blog/post/infrastructure-automation-on-aws-cloudformation-sam-and-terraform-for-iac)

## [Infrastructure Automation on AWS: CloudFormation, SAM, and Terraform for IaC](/blog/post/infrastructure-automation-on-aws-cloudformation-sam-and-terraform-for-iac)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [Infrastructure as Code](/blog/categories/infrastructure-as-code)
-   [Cloud Native](/blog/categories/cloud-native)
-   [DevOps](/blog/categories/devops)
-   [Automation](/blog/categories/automation)

Introduction This post covers Infrastructure as Code (IaC) and how it fits into a Cloud Native AWS environment: what IaC gives you, and how CloudFormation, AWS SAM, and Terraform each handle a dif

[#IaC](/blog/tags/iac)[#AWS CloudFormation](/blog/tags/aws-cloudformation)[#AWS SAM](/blog/tags/aws-sam)+6 tags

[read more](/blog/post/infrastructure-automation-on-aws-cloudformation-sam-and-terraform-for-iac)

[![AWS CloudFormation for Infrastructure as Code (IaC)](/_astro/hero.DW2mCCZ1_Z1qXfDg.webp)](/blog/post/aws-cloudformation-for-infrastructure-as-code-iac)

## [AWS CloudFormation for Infrastructure as Code (IaC)](/blog/post/aws-cloudformation-for-infrastructure-as-code-iac)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [CloudFormation](/blog/categories/cloudformation)
-   [Infrastructure as Code](/blog/categories/infrastructure-as-code)
-   [DevOps](/blog/categories/devops)
-   [Cloud Automation](/blog/categories/cloud-automation)

Introduction AWS CloudFormation is one of the core Infrastructure as Code (IaC) tools on AWS. It lets you declare your infrastructure using JSON or YAML templates, which simplifies creation and ma

[#AWS CloudFormation](/blog/tags/aws-cloudformation)[#IaC](/blog/tags/iac)[#JSON](/blog/tags/json)+7 tags

[read more](/blog/post/aws-cloudformation-for-infrastructure-as-code-iac)

[![Orchestrating Infrastructure with Terraform](/_astro/hero.D2PoOOZD_2bwX4C.webp)](/blog/post/orchestrating-infrastructure-with-terraform)

## [Orchestrating Infrastructure with Terraform](/blog/post/orchestrating-infrastructure-with-terraform)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [Terraform](/blog/categories/terraform)
-   [Infrastructure as Code](/blog/categories/infrastructure-as-code)
-   [DevOps](/blog/categories/devops)
-   [Cloud Provisioning](/blog/categories/cloud-provisioning)
-   [AWS](/blog/categories/aws)

Introduction Terraform is a tool for infrastructure orchestration that lets you create and manage infrastructure across multiple cloud providers. With Terraform, you provision resources on AWS by

[#Terraform](/blog/tags/terraform)[#IaC](/blog/tags/iac)[#AWS Provisioning](/blog/tags/aws-provisioning)+7 tags

[read more](/blog/post/orchestrating-infrastructure-with-terraform)

[![Understanding Infrastructure as Code (IaC)](/_astro/hero.D6yb7pOQ_Z2ptmwB.webp)](/blog/post/understanding-infrastructure-as-code-iac)

## [Understanding Infrastructure as Code (IaC)](/blog/post/understanding-infrastructure-as-code-iac)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [Infrastructure as Code](/blog/categories/infrastructure-as-code)
-   [DevOps](/blog/categories/devops)
-   [Cloud Computing](/blog/categories/cloud-computing)
-   [Automation](/blog/categories/automation)
-   [Software Engineering](/blog/categories/software-engineering)

Introduction Infrastructure as Code (IaC) manages infrastructure through code instead of manual configuration. Instead of clicking through consoles to set up servers, networks, and storage, you de

[#IaC](/blog/tags/iac)[#AWS CloudFormation](/blog/tags/aws-cloudformation)[#Terraform](/blog/tags/terraform)+7 tags

[read more](/blog/post/understanding-infrastructure-as-code-iac)

[![Best Practices for Infrastructure Automation in a Cloud Native AWS Environment](/_astro/hero.CTyi0Kde_16WUz4.webp)](/blog/post/best-practices-for-infrastructure-automation-in-a-cloud-native-aws-environment)

## [Best Practices for Infrastructure Automation in a Cloud Native AWS Environment](/blog/post/best-practices-for-infrastructure-automation-in-a-cloud-native-aws-environment)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [Cloud Native](/blog/categories/cloud-native)
-   [DevOps](/blog/categories/devops)
-   [Infrastructure Automation](/blog/categories/infrastructure-automation)
-   [Best Practices](/blog/categories/best-practices)

Introduction Infrastructure automation is core to running a cloud native AWS environment well. This post covers the best practices for security and compliance, CI/CD pipelines, monitoring and scal

[#AWS Automation](/blog/tags/aws-automation)[#Infrastructure as Code (IaC)](/blog/tags/infrastructure-as-code-iac)[#CI/CD Pipelines](/blog/tags/cicd-pipelines)+7 tags

[read more](/blog/post/best-practices-for-infrastructure-automation-in-a-cloud-native-aws-environment)

6 related posts
