Introduction

Nowadays many Infrastructures as Code tools are available for building cloud applications, for example, Serverless Framework and AWS SAM are both popular choices. In this article, we will take a look at the differences between Serverless Framework and AWS SAM.

What is Infrastructure as Code IaC?

Infrastructure as Code (IaC) is the provisioning of infrastructure using code instead of manually creating resources. Infrastructure specification handling at the code level becomes easy through IaC frameworks. Furthermore, IaC helps with automating infrastructure provisioning, so the developer does not need to manually create and manage cloud infrastructure resources during application deployment.

If you want to download some templates from our team, HERE.

What is AWS SAM (Serverless Application Model)?

The AWS Serverless Application Model (SAM) is an open-source framework for building serverless applications. It provides shorthand syntax to express functions, APIs, databases, and event source mappings. With just a few lines per resource, you can define the application you want and model it using YAML. During deployment, SAM transforms and expands the SAM syntax into AWS CloudFormation syntax, enabling you to build serverless applications faster.

Source

What is Serverless Framework?

Serverless Framework is a widely used open-source IaC tool that allows you to build and deploy serverless applications on multiple cloud providers. Serverless Framework supports infrastructure code specifications in YML file format (e.g serverless.yml) and transforms that into a specific cloud provider-supported template format.

Source

Serverless Guru specializes in leveraging Serverless Framework to build production scale serverless applications for companies like AirCanada, Hyatt, and Lottery Inc.

Comparison Between Serverless Framework and AWS  SAM

Links: Strong Plugin Ecosystem
Links: Getting Started, Latest Developer Guide

Serverless Framework IaC YAML Example - AWS Lambda Deploy

Serverless Framework is a simple abstraction where a few lines of YAML can create a bunch of resources in the background. An example of this is AWS IAM permissions, when you create an AWS Lambda function using Serverless Framework you will automatically get basic AWS IAM permissions for logging and monitoring.

The Serverless Framework variables system is very flexible which allows you to do dynamic include based on the existence of other parameters, SAM variables are much closer to CloudFormation.

AWS SAM IaC YAML Example - AWS Lambda Deploy

AWS SAM feels similar to AWS Cloudformation with minor syntax improvements with overall fewer abstractions taking place than Serverless Framework. Both still work well when building Serverless applications, but it depends on your team's comfort level.

Conclusion

Serverless Framework and AWS SAM are both good tools for Infrastructure as Code management, but which should I use? There is no comparison of which is better over the other, since each framework has its own strengths and capabilities that make developer life easier. This means that the framework you should choose is the one that works best for your project use cases and team.