Ruby Serverless Framework
Branch: master
Clone or download
tongueroo Merge pull request #204 from CodingAnarchy/boot-missing-env
Fix for error message on booting with missing database environment
Latest commit 91908df Feb 18, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci ignore Gemfile.lock Feb 9, 2019
.codebuild allow test script to run locally Aug 25, 2018
.github improve github templates Jan 30, 2019
bin replace ENV[DEBUG] with ENV[JETS_DEBUG], conflicts with some other li… Aug 27, 2018
docs update docs Feb 18, 2019
exe stake: working megamode, fix code building Oct 20, 2018
lib Update booter.rb Feb 18, 2019
readme Official AWS Ruby Support Dec 12, 2018
spec Kinesis Event support Feb 16, 2019
vendor update vendor/jets-gems Jan 31, 2019
.gitignore ignore Gemfile.lock Feb 9, 2019
.gitmodules remove vendor/jets-html-sanitizer Jan 11, 2019
.python-version checkpoint: working python lambda executor wrapper Aug 4, 2018
.rspec checkpoint: remove require spec_helper Aug 3, 2018
.ruby-version fix gem replacer for macosx by using rsync to copy Dec 14, 2018 1.8.6 release Feb 17, 2019
Dockerfile rename dockerfiles Aug 5, 2018
Dockerfile.base integration specs Aug 6, 2018
Gemfile remove vendor/dynomite Jan 10, 2019
Guardfile lam process controller working Oct 24, 2017
LICENSE.txt Update copyright notices to 2019 [ci skip] Jan 5, 2019
Procfile fix specs Nov 22, 2017 Update Feb 9, 2019
Rakefile remove spec:acceptance task, doesnt work Sep 25, 2018 Thanks Nate Clark! Jan 1, 2019
buildspec.yml comment out test for now Aug 8, 2018
jets.gemspec Kinesis Event support Feb 16, 2019

Ruby and Lambda splat out a baby and that child's name is Jets.

Build Status CircleCI Gem Version Support

Upgrading: If you are upgrading Jets, please check on the Upgrading Notes.

What is Jets?

Jets is a Ruby Serverless Framework. Jets allows you to create serverless applications with a beautiful language: Ruby. It includes everything required to build an application and deploy it to AWS Lambda.

It is key to understand AWS Lambda and API Gateway to understand Jets conceptually. Jets maps your code to Lambda functions and API Gateway resources.

  • AWS Lambda is Functions as a Service. It allows you to upload and run functions without worrying about the underlying infrastructure.
  • API Gateway is the routing layer for Lambda. It is used to route REST URL endpoints to Lambda functions.

The official documentation is at Ruby on Jets.

Refer to the official docs for more info, but here's a quick intro.

Jets Functions

Jets supports writing AWS Lambda functions with Ruby. You define them in the app/functions folder. A function looks like this:


def lambda_handler(event:, context:)
  puts "hello world"
  {hello: "world"}

Here's the function in the Lambda console:

Though simple functions are supported by Jets, they do not add much value as other ways to write Ruby code with Jets. Classes like Controllers and Jobs add many conveniences and are more powerful to use. We’ll cover them next.

Jets Controllers

A Jets controller handles a web request and renders a response. Here's an example:


class PostsController < ApplicationController
  def index
    # renders Lambda Proxy structure compatible with API Gateway
    render json: {hello: "world", action: "index"}

  def show
    id = params[:id] # params available
    # puts goes to the lambda logs
    puts event # raw lambda event available
    render json: {action: "show", id: id}

Helper methods like params provide the parameters from the API Gateway event. The render method renders a Lambda Proxy structure back that API Gateway understands.

Jets creates Lambda functions for each public method in your controller. Here they are in the Lambda console:

Jets Routing

You connect Lambda functions to API Gateway URL endpoints with a routes file:


Jets.application.routes.draw do
  get  "posts", to: "posts#index"
  get  "posts/new", to: "posts#new"
  get  "posts/:id", to: "posts#show"
  post "posts", to: "posts#create"
  get  "posts/:id/edit", to: "posts#edit"
  put  "posts", to: "posts#update"
  delete  "posts", to: "posts#delete"

  resources :comments # expands to the RESTful routes above

  any "posts/hot", to: "posts#hot" # GET, POST, PUT, etc request all work

The routes.rb gets translated to API Gateway resources:

Test your API Gateway endpoints with curl or postman. Note, replace the URL endpoint with the one that is created:

$ curl -s "" | jq .
  "hello": "world",
  "action": "index"

Jets Jobs

A Jets job handles asynchronous background jobs performed outside of the web request/response cycle. Here's an example:


class HardJob < ApplicationJob
  rate "10 hours" # every 10 hours
  def dig
    puts "done digging"

  cron "0 */12 * * ? *" # every 12 hours
  def lift
    puts "done lifting"

HardJob#dig runs every 10 hours and HardJob#lift runs every 12 hours. The rate and cron methods created CloudWatch Event Rules. Example:

Jets Deployment

You can test your application with a local server that mimics API Gateway: Jets Local Server. Once ready, deploying to AWS Lambda is a single command.

jets deploy

After deployment, you can test the Lambda functions with the AWS Lambda console or the CLI.

AWS Lambda Console

Lambda Console

Live Demos

Here are some demos of Jets applications:

Please feel free to add your own example to the jets-examples repo.

Rails Support

Jets Afterburner Mode provides Rails support with little effort. This allows you to run a Rails application on AWS Lambda. Also here's a Tutorial Blog Post: Jets Afterburner: Rails Support.

More Info

For more documentation, check out the official docs: Ruby on Jets. Here's a list of useful links:

Learning Content