Lamby

This last weekend at Hack Ridge, I worked on a project called Lamby. Lamby is a super simple platform for serverless, function-driven development. It works by defining individual API routes as functions which return string values. I'm really happy with the progress that I made; the app is currently live on https://www.lamby.xyz.

Getting started with lamby

In lamby, the basic unit of computation is a function. Each "function" has a main procedure:

def main(session):
       return "<h1>test</h1>"

This procedure returns a string which is then returned when the route to the function has been GETed.

The Session object

In lamby, the session variable that is passed to every function is a mutable dictionary that is shared between all sessions of all functions.

The Request object

In Lamby, all POST functions are passed a request object that has information about the request that has been performed. An example request object looks like:

{'path': '/query/example',
'args': {'a': 2},
'method': 'POST',
'form': {}}

Using modules

Lamby allows for the creation of shared modules which can then be referenced in functions. For example, if you made the following module:

def double(input):
      return input * 2

and named it test, then in a function you could reference it with the include statement:

include test
def main(session):
      return double("abc")

and use its functions.

Implementation

I built a simple server using Flask, uWSGI, nginx, and Docker. The website itself is a simple Flask application, run through uWSGI and served through nginx. The main application runs as a Docker container, but is also able to spin up sibling containers for each API call, so arbitrary code can be adequately sandboxed.

Future Goals

During the hackathon, I did end up implementing the Stripe API, with the goal of monetizing API requests. I'm considering pursing expanding Lamby to encompass and containerize all of the necessities to make functional web apps.