Introducing Lambdasync: A quest for easy deploys of JSON APIs to AWS Lambda

One of my passions in world of tech right now is Function as a Service, or FaaS for short.

The premise is as simple as it is alluring, write a function that handles an incoming event (commonly a http request) and does something with it.

exports.handler = function(event, context, callback) {  
  callback(null, {
    statusCode: 200,
    message: "Everything is awesome"
  })
};

Deploy this to a FaaS vendor and you have an auto scaling service that will respond with awesomeness to any number of requests and you didn't have to configure any servers, set up any environments or auto scaling group policies.

You are delegating the whole task of setting up servers to scale and be secure to someone else who hopefully knows the area better than you. So that you can focus on just coding a good service, which can be hard enough. 🙂

Serverless architecture

FaaS falls under the umbrella och serverless architecture, along with PaaS (Platform as a Service). Zeit's Now is a great PaaS product that I have taken a lot of inspiration from when creating Lambdasync.

The difference between Now and FaaS is basically that FaaS only let's you write a handler function, very similar to an Express route handler, whereas Now gives you a platform, or environment where you can run Express yourself (or whatever other server code you want).

Another source of inspiration was Webtask.io, a FaaS product by Auth0. Both Now and Webtask have in common that they come with CLI tools, installable by npm, require very little setup and only one or two commands to get your service online.

To get a publicly available API on AWS Lambda requires a lot more work and poking around in the near unusable AWS control panels.

Lambdasync

I wanted to create something equally easy for Lambda, something simple that in the background just uses the AWS SDK for Node.js to set everything up for you.

This is the flow I came up with:

npm install -g lambdasync

// Create a new project
lambdasync new my-project  
cd my-project

// Deploy
lambdasync  

You are prompted for your AWS credentials, your region and your desired function name and what you get back is a public API URL, copied to your clipboard, running the basic handler function I used as an example above.

Lambdasync has created a new project folder for you, with an index.js file that you can now edit to make your API do what you want.

Writing a more useful handler function

I have created a small Example project with a tutorial post to go with it on how to build a basic REST Create, Read, Update, Delete API.

The official AWS docs also has some good info on how to write handler functions.

What's next?

In short, plugin support. I'm currently looking at a few plugin ideas, including instant GraphQL endpoints from GraphQL schemas, instant REST endpoints from JSON API schemas and authentication.