Installing faasd

cgi was good, serverless is better

Published February 8, 2021 #faasd, #serverless, #cloud, #openfaas

Recently I came across an article on faasd, and I thought I'd give it a try and see how easy it is to use. Server templating is an easy way to create a server with DNS, and following the whole disposability principals, we'll whip something up and see how it goes.

What is faasd?

Functions as a service are a way to easily package up simple functions as an API, with a minimal amount of overhead. Firing up a whole rails project, configuring a server or spinning up a heroku instance, kubernetes cluster, etc may be overkill for a simple proof of concept, and that proof of concept may be enough to last you a long time. AWS Lambda is the more common form of serverless functions, but that means you have to sign up for the whole AWS console, which I can barely understand. faasd is a very stripped down platform that you can run on your VPS or even a RaspberryPI, which will let you throw up something simple without having to, you know, deploy kubernetes.

Set up the server

We first need to setup a clean server. I'm going to use debian since I always do, but the installation instructions say to use Ubuntu.

resource "dnsimple_record" "faas" {
  domain = var.dnsimple_domain
  name   = "faas"
  value  = digitalocean_droplet.faas.ipv4_address
  type   = "A"
  ttl    = 3600

resource "digitalocean_droplet" "faas" {
  name     = "faas"
#  image    = "ubuntu-18-04-x64"
  image    = "debian-10-x64"
  size     = "s-2vcpu-2gb"
  monitoring = true
  region   = var.do_region
  ssh_keys = [

Then terraform apply to create it.

Install faasd

Ssh into your server as root and run the following commands:

  export # Change to yours
  export    # Change to yours

  apt-get install -y git
  cd /tmp
  git clone --depth=1
  cd faasd


  cat /var/lib/faasd/secrets/basic-auth-password

The last line will print out the auth password which you will need for the ui and to use the cli.

We can run this on the remote server using:

ssh <

Just visit your domain to see the UI. The username is admin and the password was printed out by the previous command.

Install faas-cli

My server is so lets first install the cli tool, and then point it to it.

  curl -sSL | sudo sh
  export OPENFAAS_URL=
  ssh cat /var/lib/faasd/secrets/basic-auth-password | faas-cli login --username admin --password-stdin

We can then deploy our first function by

  faas-cli store deploy nodeinfo

And run it with:

Hostname: localhost

Arch: x64
CPUs: 2
Total mem: 1998MB
Platform: linux
Uptime: 269013

Nice and easy. A list of functions available from the store can be found with

  faas-cli store list

Templates and registries

The basic idea is that we pull down one of the templates, code it up, and then push it up to our server. The way that it works is that we build the container, push it to a registry, and then tell our faasd server to pull that container from a registry and deploy it.

To get a list of available templates:

  faas-cli template store list

Writing a node12 function

We'll ceate a new one (I'm taking this code from the serverless for everyone else book) and we are doing to push it to docker hub. I'm already logged in as wschenk so that's what I'm setting the OPENFAAS_PREFIX to.

  export OPENFAAS_PREFIX=wschenk

  faas-cli new --lang node12 starbot

Lets install the axios package.

  cd starbot
  npm install --save axios

Then lets change the starbot/handler.js to

const axios = require("axios")

module.exports = async (event, context) => {
    let res = await axios.get("")
    let body = `There are currently ${} astronauts in space.`
    return context
        .headers({"Content-type": "application/json"})

Then we deploy the function

  faas-cli up -f starbot.yml

And we can run it with:

There are currently 7 astronauts in space.


Command as a cloud function

Lets look at how to package up a command as a function.

faas-cli new --lang dockerfile fortune

Then we edit the fortune/Dockerfile. Add we are adding here is RUN apk add fortune and setting the fprocess to fortune.

FROM as watchdog

FROM alpine:3.12

RUN mkdir -p /home/app
RUN apk add fortune

COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
RUN chmod +x /usr/bin/fwatchdog

# Add non root user
RUN addgroup -S app && adduser app -S -G app
RUN chown app /home/app

WORKDIR /home/app

USER app

# Populate example here - i.e. "cat", "sha512sum" or "node index.js"
ENV fprocess="fortune"
# Set to true to see request in function logs
ENV write_debug="false"


HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1

CMD ["fwatchdog"]

Then you can build and deploy with

faas-cli up -f fortune.yml

Which now is available as:

When I get real bored, I like to drive downtown and get a great
parking spot, then sit in my car and count how many people ask me if
I'm leaving.
		-- Steven Wright

The whole process took me under a minute for the first time that I did it, so that's super cool.


OpenFaas uses what they call the PLONK Stack, which is a goofy but fun name, but the P stands for Prometheus. Lets see how that works.

First we setup a ssh tunnel so we can connect to the local prometheus instance.

  ssh -L 9090:

Once this tunnel is up, we can connect to Prometheus locally.


Now on your faas server, edit /var/lib/faasd/docker-compose.yaml to add the grafana service.

      # we assume cwd == /var/lib/faasd
      - type: bind
        source: ./grafana/
        target: /etc/grafana/provisioning/
      - CAP_NET_RAW
      - prometheus
      - ""

We need to create the grafana directory and restart everything:

  mkdir -p /var/lib/faasd/grafana/
  systemctl daemon-reload && systemctl restart faasd

Finally on our local machine we need to open up an ssh tunnel to grafana so we can access. In my case:

  ssh -L 3000:

Add your prometheus datasource, pointing to http://prometheus:9090 and you are good to start adding panels.

In closing

This makes it really easy to quickly spin something up. Getting logging and monitoring built in "for free" is a huge leg up on spinning up your own solutions. I've haven't jumped too much into the kubernetes bandwagon, but this makes it so simple to expose a tiny bit of functionality in a way that seems so easy to maintain.

If you usecase is about gluing a couple of things together this is really pretty fascinating!







Read next

See also

Effigy, a distributed social data layer

Scuttlebutt is awesome, let’s run with it

I grew up in the world of BBSes, Usenet, and, to some extent, UUCP before that. This was fun – a world wide network all built up by volunteers sharing. Since we are all carrying supercomputers around now with massive idle storage and bandwidth, let's think about how we can recreate some of that fun, independent data sharing with modern web technologies, specifically Websockets and WebRTC. All you need is the computer that you already have with you.

Read more