22.09.2018 | Big Update: The 'event' parameter passed to the handler has changed from Hash to Struct. Learn more.
22.09.2018 | Latest gem release: 0.1.15 - please run 'gem update faastruby'

FaaStRuby

Join the chat - Docs

What

Fast, lightweight and scalable serverless platform built for Ruby developers.

Run Ruby functions at scale as fast as Ruby can be - with zero cold start time.

Why

After signing the We want FaaS for Ruby petition, I got curious about what it takes to build a serverless platform from scratch.

See it in action

Demo server specs: 2 Digital Ocean droplets with 1 vCPU / 1GB Mem / 25GB Disk ($5/mo)
Run it a few times so you get a sense of the average execution time.

Hello, World!




def handler event
  response = {
    "Hello" => "World!"
  }
end




Query Yahoo Weather API

require 'weather-api'
require 'oj'

def handler event
  body = Oj.load(event.body)
  weather = Weather.lookup_by_location(body['location'], Weather::Units::CELSIUS)
  response = {
    title: weather.title,
    temperature: "#{weather.condition.temp}C",
    conditions: weather.condition.text
  }
end

How it works

You trigger functions through a HTTPS endpoint. Your function will receive the request body, query parameters and headers.

Function endpoints accept GET, POST, PATCH, PUT and DELETE verbs.

Your function entrypoint is the method handler. This method must be defined inside of a file named handler.rb. This method must return a Hash, Array or String.

# my-function/handler.rb
require 'a_cool_gem'

def handler event
  # event.body #=> The request body
  # event.query_params #=> The request URL query parameters
  # event.headers #=> The request readers
  do_cool_stuf_with event
  # Return Hash, Array or String
end

# my-function/Gemfile
source 'https://rubygems.org'
gem 'a_cool_gem'

Try it

1. Install the gem

$ gem install faastruby

2. Initialize a folder for your functions. The command also generates an example function that echoes back what you send to it.

$ faastruby new FOLDER_NAME

3. Push it to a remote repository

$ cd FOLDER_NAME
$ git remote add origin git@gitlab.com:USER/my-repo.git
$ git push --set-upstream origin master

4. You need to deploy your functions to a workspace. Pick a workspace name that is unique. I will use the name 'my-workspace' in the example below, but you should try using your Github username, for example.
Create the workspace providing the name and the git repository URL.

$ faastruby workspace create -name my-workspace -repo 'git@gitlab.com:USER/my-repo.git'
Workspace 'my-workspace' created.
Credentials file '~/.faastruby' updated.
Add the following SSH key to the GIT repository 'git@gitlab.com:USER/my-repo.git' with *READ-ONLY* permission.

ssh-rsa AAAAB3NzaC1yc2E...

Then run 'faastruby workspace deploy -name my-workspace' to deploy.

5. Add the ssh key above to git@gitlab.com:USER/my-repo.git as a deploy key.

6. Deploy the functions to your workspace.

$ faastruby workspace deploy -name my-workspace

7. Run it!

$ faastruby run my-workspace/example -body '{"hello": "world"}' -method post

It can read from STDIN.

$ echo '{"hello": "world"}' | faastruby run my-workspace/example -method post -stdin

If you want to feel in control...

$ curl -X POST -d '{"hello":"world"}' 'https://api.faastruby.io/my-workspace/example'

Combine them and automate some tasks.

$ faastruby run my-workspace/check-app-status | faastruby run my-workspace/send-everyone-a-text -method post -stdin

8. You can also delete the workspace.

$ faastruby workspace delete -name my-workspace

9. Build lots of functions and share them with fellow Ruby devs!

Who are you?

I'm Paulo Arruda. Who are you?