A tl;dr guide to Serverless Framework

mdsadiq
Product Ride
Published in
3 min readMay 10, 2020
Photo by Joseph Chan on Unsplash

Imagine you are suddenly pushed into a serverless project and you don’t know where to start ? Your head is already spinning with the huge documentation ​that serverless provides you. What do you do ?
You call up your friend who has worked on serverless framework some time and ask for quick intro to get you quickly up and running, right ?

Well, this article is that friend 😉💁. A Too Long; Didn’t Read Version

Now,

What is Serverless Framework? what does it do ?

The Serverless Framework helps you develop and deploy your AWS Lambda functions, along with the AWS infrastructure resources they require.

Note that serverless framework, is not limited to aws but also other cloud providers like Google Cloud.

The starting point of any infrastructure built using serverless framework is serverless.yml

For easy understanding of experienced developers, this is the best analogy for serverless.yml. Not to be compared as 1-to-1, but to get better overview.

What package.json is to npm, serverless.yml file is to serverless framework and much more.

The serverless.yml file is the blueprint of your cloud architecture, it has everything from language, roles, restrictions to cloud provider and resources.

Serverless Framework goes through serverless.yml and prepares a cloud formation config which in turn is used to deploy the infrastructure in predictable manner.

Before we start, you should be aware of,
💡 Cloud Formation: It is a service provided by aws. It helps in creating the infrastructure(ie) API gateway, lambda, Database etc just by using code. So we pass this code to cloud formation and it turn creates the infrastructure.

In a nutshell the serverless framework converts your json code to cloud formation template and validates your code. If it is good, serverless will use cloud formation to push the code and deploy your infrastructure in aws.

Now you know how serverless works, what next ?

We are going to create mental models of, what is what of serverless, To do that, i will show you two things,

  1. A cheatsheet per se. It gives the sections that are present in serverless and overview of what each section does.
  2. A stripped down sample code that helps you to compare with cheatsheet to create the mental model.

Once this mental model is created you can easily start using infrastructure with quick understanding of what each part of configuration does. Also at the end i will share the link of all sample serverless repositories[shared by serverless themselves] that you can look, to get even better understanding.

The Cheatsheet
Note that the name on the left most boxes are reserved words, so it will be present in all files.

if you have got a little understanding from the above picture, Let’s have a look at the sample serverless file that will give even more clarity.

The Code

serverless.yml

When comparing with Cheatsheet and repository you will be able to understand more.

Ideally output section is an interesting part, it takes the resource from our code and returns cloud specific(aws) name, that can be used by other resource. In short, it is used to share resource from one stack to another. oh wait ,what is stack ?

A stack is set of resource that is put together, ex1: a s3 and its lambda function, ex2 a DB with its lambda function.

Now you can go into serverless world bravely, hope you enjoyed 🤞

link for examples https://github.com/serverless/examples

--

--

mdsadiq
Product Ride

First do it. Then do it right. Then do it better. Javascript everything. Find me at https://www.linkedin.com/in/muhammad-sadiq-ali/