faas

module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2020 License: MIT

README

FAAS

example workflow name

A simple Functions-as-a-Service(FaaS) platform using Docker containers for the purpose of experimentation/learning

Dependencies

  • Only works in Linux and tested on Ubuntu
  • Must have Docker daemon installed and running

Install CLI tool

NOTE: Currently only Linux is supported due to extra effort required to interact with Docker containers on Mac OS and Windows because of the Docker virtual machine

The latest Linux binary can be found here

Quick Local Demo:

Start the server:

faas start

Create and invoke a function

In another terminal:

mkdir examplefn
cd examplefn
faas init
faas build
faas invoke examplefn

Output: Response: {"hello":"world"}

Example

NOTE: Only javascript is currently supported for writing functions

If you are running locally start the faas server first: faas start
Next, create a new working directory for your function. cd into it and then run faas init.
After running faas init, open index.js in your code editor to modify your function.

Here is an example function that takes in an array of numbers are returns the sum:

// takes an array of numbers and returns the sum
module.exports = (context, cb) => {
  let sum
  for (let num of context.numbers) {
    sum += num
  }

  // respond to the caller with the sum of numbers
  return cb({sum: sum})
}

Run faas build in your functions working directory to deploy the function to the server.

Now lets put some input data into a JSON file.

input.json:
{
  "numbers": [6,4,13]
}

Now invoke the function and pass it your array of numbers:
faas invoke fn -d input.json

Output: Response: {"sum":23}

REST API

Add Function

Adds a new function and returns the url used to invoke it

URL : /functions/

Method : POST

Data constraints

Provide name of the function and a base64 encoded tar file containing the directory with the function code inside

{
    "name": "<string>",
    "file": "<base64 encoded tar file containing function code>"
}

Data example All fields must be sent.

{
    "name": "add",
    "file": "Zm4ueWFtbAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAwMDA3NTUAMDAwMDc2NQAwMDAwMDI0ADAwMDAwMDAwMDE2ADEzNzcwNjY1NzM3ADAxNDI3MAAgMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwMDAwNjAwADAwMDAwMDAAMDAwMDAwMAAwMDAwMDAwMDMwMwAwMDAwMDAwMDAwMAAwMTExNjMAIDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAdXN0YXIAMDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDAwMDAwMAAwMDAwMDAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARlJPTSBub2RlOjEyCgojIENyZWF0ZSBhcHAgZGlyZWN0b3J5CldPUktESVIgL3Vzci9zcmMvYXBwCgojIEluc3RhbGwgYXBwIGRlcGVuZGVuY2llcwpDT1BZIHBhY2thZ2UqLmpzb24gLi8KClJVTiBucG0gaW5zdGFsbAoKIyBCdW5kbGUgYXBwIHNvdXJjZQpDT1BZIC4gLgoKRVhQT1NFIDgwODAKQ01EIFsgIm5vZGUiLCAic2VydmVyLmpzIiBd"
}

Success Response

Condition : If the function data is valid.

Code : 200 OK

Content example

{
    "invoke": "http://localhost:5555/functions/:name",
}

Error Responses

Code : 400 BAD REQUEST

Content example

{
    "message": "Failed to deploy function"
}

Invoke Function

Invokes a function

URL : /functions/:name

Method : POST

Data constraints

Provide the input data to the function in the request body

{
  "anyInputFields": "anyValues"
}

Data example

{
    "numbers": [7,33,12,18],
}

Success Response

Condition : If the function exists.

Code : 200 OK

Content example

{
    "response": "[JSON function result]",
}

Error Responses

Code : 400 BAD REQUEST

Content example

{
    "message": "[Error message]"
}

Roadmap:

  • Pass input data to the function container and recieve a response to return to the caller
  • Run unit tests automatically on push/PR via Github Actions
  • Automatically deploy a new binary release on PR merge into master via GitHub Actions
  • Store function name/images and users/apps in a datastore
  • Push deployed images to a docker registry and pull images when invoked
  • Decouple the gateway and runners into separate binaries so faas can be scaled across multiple machines
  • Support more programming languages

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL