The ultimate (getting started) guide to serverless

johndemian

John Demian

Posted on September 16, 2019

The ultimate (getting started) guide to serverless

For the past couple of years, I’ve been working with an awesome bunch of people over at Dashbird, where we wake up every day and make serverless technology a bit better by creating solutions for the current problems the serverless community is facing. I’ve written dozens of articles about the benefits, the problems and different reasons why you should pick up serverless and how to make it work better. This article will be a summary of everything you need to know to get started with serverless.

Let’s start with the very beginning:

What is serverless

In terms of definitions, serverless is often assumed to be Function as a Service (FaaS). That's not entirely true. Serverless is so much more. It should be viewed as an event-based system for running code. Meaning, you use various services to create business logic without caring about any servers. You're abstracting away the infrastructure altogether. Perfect examples can be hosting static websites on S3, using serverless databases like DynamoDB or Aurora Serverless, and of course, running code without managing servers with Lambda.

Serverless is great if you have sudden traffic spikes that need to be detected and handled instantly. The application is even completely shut down if there's no traffic at all. You only pay for the resources you use. No usage, no costs, quite simple!


Image Courtasy of Cleveroad.com

Serverless service providers

Here are the most popular serverless platforms out there to help shed some light on the current options available to developers

1. AWS Lambda

2. Microsoft Azure

3. Google App Engine

4. Google Cloud Functions

5. IBM OpenWhisk

To learn more about each individual platform check out this post.

Get started with serverless

To begin working on serverless takes very little effort. While there are a number of services provides to chose from, I’m going to talk about AWS and AWS Lambda to keep things easier for both of us. I’ll start by describing the limitations that you have with AWS Lambda, this way you’ll know exactly how much you can push your system.

Function memory allocation: 128 MB to 3,008 MB, in 64 MB increments.
Function timeout: 900 seconds (15 minutes)
Function environment variables: 4 KB
Function resource-based policy: 20 KB
Function layers: 5 layers
Function burst concurrency: 500 - 3000 (varies per region)
Invocation payload: 6 MB (synchronous)/ 256 KB (asynchronous)
Deployment package size: 50 MB (zipped) or 250 MB (unzipped)
/tmp directory storage: 512 MB
Execution processes/threads: 1,024

Now that we got this out of the way let’s move on to the next part.

How to create a simple Lambda function

There are two ways to do so, one would be to upload your code directly through the AWS interface which is not a bad way to go but let’s face it, you won’t be able to do this for a big project with multiple microservices that have a lot of small functions.
So while doing uploading functions one by one is ok-ish what you need is a platform that allows you to connect to AWS (or any other service provider) and leverage that to get the most out of everything that serverless technology has to offer.

Serverless platform

While the name is confusing, the Serverless platform is an awesome way to build, develop and scale serverless applications. It’s free to use and the community support that revolves around it is truly incredible.

There are lots of different ways to go when picking a serverless framework to work with and besides having over 25000 github stars and being the number one tool for deploying serverless apps, I’d recommend serverless technology because of its cloud-agnostic approach. While I don’t necessarily suffer from the vendor lock-in syndrome everyone is complaining I like the idea of being able to deploy on a number of different services without having to jumps through hurdles, hoops and everything in between.

Setting up the project is straight forward, once serverless is installed on your system you initialize the serverless framework by using:

serverless login

This will get you set up and logged into AWS and then you can start publishing your Lambdas. From this point forward you can start building your application either from scratch or by using any one of their boilerplate.

serverless create --template aws-nodejs --path sls-express-mongodb

This installs and pre-configures almost everything you need to get a head start on a powerful API that can support efficiently your entire application.

Here are a list of a few great tutorials to get you started with serverless in no time:

1. Building a serverless contact form with AWS Lambda and AWS SES

2. Serverless with AWS - Image resize on-the-fly with Lambda and S3

3. A crash course on Serverless APIs with Express and MongoDB

4. Create your first website with serverless in 15 minutes

5. Serverless with AWS - Triggering Lambda with SNS Messaging

Alright, that’s all I’ve got on the subject but since there are so many updates I’ll try to keep it updated. If there are any resources you think are missing please give me a heads-up on twitter @johndemian .

💖 💪 🙅 🚩
johndemian
John Demian

Posted on September 16, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related