Serverless logo

Serverless Framework.

Introduction

I started working on a new interesting customer case. The team has already used Serverless Framework quite a lot. But for me Serverless Framework was a new tool. I have mostly used Terraform and Pulumi as my multi-cloud IaC tool, but I was delighted that I have now a chance to learn a third excellent multi-cloud IaC tool for my cloud toolbelt.

You might also want to read my Terraform vs. Pulumi Experiences in which I compare the two main stream IaC tools that I have used this far.

By the way. I often write these blog posts as part of my own learning, just like I did with this blog post. I was learning Serverless Framework and as part of the learning process I made myself to verbalize what Serverless Framwork is, what it can be used for, etc. - a good learning method. Therefore, most probably you don’t find any special information in this blog post that you couldn’t find in Serverless Framework documentation. But perhaps these blog posts are also an easy-to-read short introductions to various topics.

What is Serverless Framework?

Serverless Framework is an IaC tool and a service. Serverless Framework provides a cli tool that you can use to deploy your serverless infrastructure and also to interact with the service. Serverless Framework provides also a service called Dashboard that you can use to set up connections to your cloud providers and interact with your infrastructure with a browser UI.

Serverless Framework is a multi-cloud tool, meaning that there are providers for various clouds. Check out if Serverless Framework supports your cloud in the Serverless Infrastructure Providers documentation.

Why Should You Use Serverless Framework?

Serverless Framework provides a nice alternative to more powerfull but also more complex IaC tools, like Terraform, Pulumi or CloudFormation. E.g. in the AWS side, you can do anything with Serverless Framework that you can do with those other IaC tools since you can quite easily create custom CloudFormation stacks as part of your Serverless IaC.

The main reason to use Serverless Framework is the simplicity of the solution. Serverless Framework has done quite a lot of effort to make the developer experience as smooth as possible when it comes to implement the IaC solution and also do the deployment.

When would you like to use Terraform or Pulumi? You can create good serverless paradigm IaC solutions just using Terraform or Pulumi, of course. Perhaps you want to use Terraform or Pulumi if your team already has a lot of infrastructure created using those tools, and you want to re-use your IaC modules and integrate Serverless entities to other infrastructure entities using those modules.

How to Get Started?

I strongly recommend to read the Serverless Framework documentation to get familiarized with the tool and service and to get a good overview and build a mental model what Serverless Framework is all about. Once you have read the documentation you should do the simple Serverless Framework tutorial - this tutorial provides you a good understanding how to use Serverless Framework cli tool and service, and how to implement the IaC solution using the tool. There is also a good video which shows you the steps of the tutorial.

Serverless Framework Dashboard

If you are doing Serverless Framework tutorial you should create a provider using Serverless Framework Dashboard, the tutorial provides good instructions for this. As part of this step Serverless Framework Dashboard connects to your AWS account and creates a CloudFormation stack which is used to deploy an AWS IAM role. This IAM role has AdministratorAccess to be able to deploy the CloudFormation stack created by your Serverless Framework solution.

If you connected your Serverless project using the sls cli with your Dashboard account, you can use the Dashboard to view quite a lot of useful information about your deployment, e.g. view invocations, errors, alerts, get various metrics, interact with the api endpoints, deployments, etc. Most of this information is available also in the AWS CloudWatch, of course.

Serverless Framework CLI

Serverless Framework has a command-line utility called serverless (or alias: sls). Using the cli tool you can do deployments, get information about the infrastructure, view logs, etc. Example:

λ> sls deploy list functions
createCustomer
  All versions: $LATEST, 2, 3
getCustomers
  All versions: $LATEST, 1, 2
λ> sls logs --function getCustomers
START
END Duration: 111.53 ms (init: 1473.41 ms) Memory Used: 99 MB
START
END Duration: 45.88 ms Memory Used: 99 MB
START
END Duration: 115.57 ms Memory Used: 103 MB

CloudFormation Stack

In the AWS cloud Serverless Framework uses CloudFormation as the IaC tool to deploy the infrastructure. I couldn’t find the CloudFormation stacks in Serverless Framework Dashboard. But you can go to the AWS Console to see the CloudFormation stacks that were deployed by Serverless Framework, or use the aws cli to view them.

As mentioned earlier, Serverless Framework creates one stack for the IAM role that is used for the actual infrastructure deployments. Then Serverless Framework creates one CloudFormation stack for each Serverless deployment. You can also add custom CloudFormation stacks as part of your Serverless Framework deployments.

Conclusions

Serverless Framework provides a nice and easy-to-use alternative to other main stream multi-cloud IaC tools like Terraform or Pulumi. Later on, I think I write another blog post comparing Serverless Framework with Terraform and Pulumi when I have more experience about how to use the tool.

The writer is working at a major international IT corporation building cloud infrastructures and implementing applications on top of those infrastructures.

Kari Marttila