This post is about serverless functions and how to implement them with the Serverless Framwork compared to OpenFaas
As part of my Bachelor Thesis “Serverless Architectures”, my boss Edmund wanted to support me and assigned me the task to implement a serverless function to gain a deeper understanding of the serverless concept. We decided to work with the Serverless Framework.
We wanted to trigger our deployment pipeline for our website, which is described in the article Womenintech Part 4: Continuous Delivery Of A Static Web Page With Jekyll, GitLab And AWS, through a simple slash command in our slack channel. The problem here was, that you can’t configure the slash command to send a HTTP POST request with a JSON payload. So we decided to use a simple serverless function which triggers our pipeline.
The Serverless Framework is a toolkit which is designed for operating serverless architectures and deploying centrally to AWS Lambda, Microsoft Azure, IBM OpenWhisk and some more providers. The first thing you need to do is install the Serverless Framework on your machine with the command ‘’’npm install -g serverless’’’. Afterwards you can choose between AWS Lambda, Microsoft Azure, IBM OpenWhisk and some more providers where your service should run. The most common supported programming languages are Node.js, Python, Java and some more.
To create a new service with a template you can use the command below (choose your favorite provider):
serverless create --template aws-nodejs | azure-nodejs | openwhisk-nodejs --path path-of-project
The template you get is configured to return a simple text message. We wanted our function to send a HTTP POST request to an API endpoint. Therefor I rewrote the code to handle this and to use custom options.
Afterwards I tested the function to see if it works as expected:
serverless invoke –f “name of function” serverless invoke –-function “name of function” (OpenWhisk)
Deploying the service to a provider can be achived with the following command:
serverless deploy (-v)
AWS and OpenWhisk use the ‘-v’ option, whereas Microsoft doesn’t.
After the deployment, we configured the slash-command to send an HTTP POST Request to the API where our function is located, when called.
OpenFaaS on the other side is a open source serverless framework to build serverless functions. They can be embedded in a Docker container, this means that you are not dependet on the programming languages that are supported by your provider. To work with it you should setup OpenFaas with Docker Swarm or with Kubernetes.
In contrast to the other providers, OpenFaaS works with orchestration platforms such as Docker Swarm or Kubernetes. It does not depend on runtimes for each supported language, therefor you can run code in any programming language.
It was really interesting for me to figure out how easy it is to configure and work with serverless functions. I very appreciate it that my colleagues support me wherever they can and that they are assigning me tasks which help me to write my Bachelor Thesis.