Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
115 lines (77 sloc) 3.17 KB

Develop your own function


Before you start development, you may want to take FaaS for a test drive which sets up a stack of sample functions from docker-compose.yml. You can then build your own functions and add them to the stack.

You can test-drive FaaS with a set of sample functions as defined in docker-compose.yml on for free, or on your own laptop.

Working on the API Gateway or Watchdog

To work on either of the FaaS Golang components checkout the "./" scripts and acompanying Dockerfiles.

Creating a function

Functions run as Docker containers with the Watchdog component embedded to handle communication with the API Gateway.

You can find the reference documentation for the Watchdog here.

Markdown Parser

This is the basis of a function which generates HTML from MarkDown:

FROM golang:1.9.7
RUN mkdir -p /go/src/app
COPY handler.go /go/src/app
WORKDIR /go/src/app
RUN go get && \
    go get

RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .

ADD /usr/bin
RUN chmod +x /usr/bin/fwatchdog

ENV fprocess="/go/src/app/app"

CMD ["/usr/bin/fwatchdog"]

The base Docker container is not important, you just need to add the watchdog component and then set the fprocess to execute your binary at runtime.

Update the Docker stack with this:

        image: alexellis2/faas-markdownrender:latest
            function: "true"
            - functions

Word counter with busybox

FROM alpine:latest

ADD /usr/bin
RUN chmod +x /usr/bin/fwatchdog

ENV fprocess="wc"
CMD ["fwatchdog"]

Update your Docker stack with this definition:

        image: alexellis2/faas-alpinefunction:latest
            function: "true"
            - functions
            fprocess: "wc"


You can optimize Docker to cache getting the watchdog by using curl, instead of ADD. To do so, replace the related lines with:

RUN apt-get update && apt-get install -y curl \
    && curl -sL > /usr/bin/fwatchdog \
    && chmod +x /usr/bin/fwatchdog \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

or with the following for Alpine based images:

RUN apk --no-cache add curl \
    && curl -sL > /usr/bin/fwatchdog \
    && chmod +x /usr/bin/fwatchdog

Testing your function

You can test your function through a webbrowser against the UI portal on port 8080.


You can also invoke a function by name with curl:

curl --data-binary http://localhost:8080/function/func_wordcount