Serverless-Sam-CLI

SAM CLI - Serverless Application Model , is a command line tool provided by AWS to easily create and manage serverless Applications.

Serverless Framework – Serverless Framework is also a tool similar to SAM but it is not limited to AWS, Serverless Framework can be used to easily create and manage serverless applications from various providers like AWS, Azure, GCP & more.

I will be listing the main differences I found between these two when used with AWS, which may help you to choose one of these.

Installation

SAM

You need to follow Operating System specific installation steps as there are multiple dependencies for SAM which are installed differently on different Operating systems. Below are some general steps to be followed irrespective of Operating System.

Serverless

For Serverless you need to follow Operating System specific instructions only for installing Node.js and if you have Node.js installed on your machine already, then using single command below your Serverless installation will be ready ‘npm install -g serverless’.

Resource Definition

SAM

SAM being an AWS specific framework, it supports managing most of the AWS resources out of the box and you can expect it to be always in sync with AWS service updates.

  • Resources are defined in a file called template.yaml
  • More verbose hence produces more lines of code compared to serverless
  • Resources are created and managed by a cloudformation stack
    Eg: Defining an API Gateway endpoint in SAM
    Events:
    GetApiEndpoint:
    Type: Api
    Properties:
    Path: /items
    Method: GET

Serverless

Serverless being a generic framework for multiple serverless platforms , it may not support all AWS services and it will always take some time to get the latest updates with respect to changes in latest AWS services.

  • Resources are defined in a file called serverless.yml
  • More readable and less code compared to SAM
  • Resources are created and  managed by a cloudformation stack
    Eg: Defining an API Gateway endpoint in Serverless
    events:
    -http:
    path: /items
    method: GET

Local Development

SAM

Can simulate API Gateway and Lambda locally without any extra dependencies and these two services are the most common requirements to run a serverless application in AWS.

Serverless

Needs extra plugins to be installed for most of the basic requirements like local development server, creating nested stacks, etc.

Deployment

SAM

On initial versions of SAM we had to run 2 different commands to build, upload and deploy and it did not support features like one step deployment and automatic deployment bucket creation which was supported in serverless framework at the same time. Latest version of SAM supports single command deployment similar to Serverless.

Serverless

We can deploy using single command ‘sls’ deploy and S3 bucket creation is taken care automatically, we can also deploy or update single function in a stack individually which is not supported by SAM.

Conclusion

Serverless and SAM both have pros and cons based on various scenarios in which they are used , so based on these observations , it is better to go with SAM if you are a developer who will be working with only AWS cloud. It is better to choose Serverless framework if you are a full time devops engineer or cloud developer who will be managing and working with different serverless providers at the same time because you can use a single framework and make use of vast community and documentation.