OpenFaaS Lab 6


Posted by Krystian Wojcicki on Monday, July 29, 2019 Tags: Guide   3 minute read

Lab 6

  • Faas-flow

As mentioned before faas-flow is a neat library helping you perform function composition.

We will use faas-flow to redo what we did in lab2.

faas template pull
faas new faas-flow-wc --lang faas-flow

Edit faas-flow-wc.yml to look like the following:

version: 1.0
  name: openfaas
    lang: faas-flow
    handler: ./faas-flow-wc
    image: faas-flow-wc:latest
      read_timeout: 120 # A value larger than `max` of all execution times of Nodes
      write_timeout: 120 # A value larger than `max` of all execution times of Nodes
      write_debug: true
      combine_output: false
      - flow.yml

and create a file called flow.yml with the following content

  gateway: "gateway.openfaas:8080" # The address of OpenFaaS gateway, Faas-flow use this to forward completion event
  # gateway: "gateway.openfaas:8080" # For K8s 
  enable_tracing: false # tracing allow to trace internal node execution with opentracing
  enable_hmac: true # hmac adds an extra layer of security by validating the event source

Modify handler.go with the following:

package function

import (
	faasflow ""

// Define provide definiton of the workflow
func Define(flow *faasflow.Workflow, context *faasflow.Context) (err error) {
		Modify(func(data []byte) ([]byte, error) {
			// do something
			return data, nil

// DefineStateStore provides the override of the default StateStore
func DefineStateStore() (faasflow.StateStore, error) {
	return nil, nil

// ProvideDataStore provides the override of the default DataStore
func DefineDataStore() (faasflow.DataStore, error) {
	return nil, nil

Next build and deploy the faas-flow function

faas build -f faas-flow-wc.yml
kind load docker-image faas-flow-wc:latest
faas deploy -f faas-flow-wc.yml --gateway $ip:31112

now to test

kwojcicki@ubuntu:~/workspace/openfaas-workshops$ curl -XPOST $ip:31112/function/faas-flow-wc -d 'Hello of the world'
{"Hello": 1, "world": 1}

Same as when we created wc-filtered however now all the function composition logic is stored outside of the function making them easier to use.