• Stars
    star
    2,438
  • Rank 18,874 (Top 0.4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ruby on Jets

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

Build Status Gem Version Support

BoltOps Badge

Please watch/star this repo to help grow and support the project.

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

What is Ruby on 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 and deploy an application to AWS Lambda.

Understanding AWS Lambda and API Gateway is key to understanding Jets conceptually. Jets map your code to Lambda functions and other AWS Resources like API Gateway and Event Rules.

  • 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.
  • EventBridge Rules are events as a service. You can automatically run Lambda functions triggered from AWS services. You decide what events to catch and how to react to them.

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:

app/functions/simple.rb:

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

Here's the function in the Lambda console:

Code Example in AWS Lambda console

Though simple functions are supported by Jets, they do not add as 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:

app/controllers/posts_controller.rb:

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

  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}
  end
end

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

Jets creates single Lambda functions to handle your Jets Controller requests. The Lambda Function handler is a shim that routes to your controller action.

Jets Routing

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

config/routes.rb:

Jets.application.routes.draw do
  resources :posts
  any "posts/hot", to: "posts#hot" # GET, POST, PUT, etc request all work
end

The routes.rb gets translated to API Gateway resources:

API Gateway Resources generated from routes in AWS console

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

$ curl -s "https://quabepiu80.execute-api.us-east-1.amazonaws.com/dev/posts" | jq .
{
  "hello": "world",
  "action": "index"
}

Jets Jobs

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

app/jobs/hard_job.rb:

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

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

Jets Jobs in AWS Lambda Console

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

CloudWatch Event Rules in AWS Console

This simple example uses Scheduled Events. There are many more possibilities, see the Events Docs.

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.

Live Demos

Here are some demos of Jets applications:

Please feel free to add your examples to the rubyonjets/examples repo.

More Info

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

Learning Content

More Repositories

1

terraspace

Terraspace: The Terraform Framework
Ruby
673
star
2

ufo

AWS ECS Deployment Tool
Ruby
219
star
3

kubes

kubes
Ruby
99
star
4

dynomite

A simple wrapper library to make DynamoDB usage a little more friendly
Ruby
52
star
5

lono

Lono CloudFormation Framework
Ruby
50
star
6

aws-inventory

aws inventory tool
Ruby
47
star
7

sonic

Multi-functional tool to manage AWS infrastructure
Ruby
27
star
8

jack

Wrapper tool to manage AWS Elastic Beanstalk environments
Ruby
26
star
9

aws-mfa-secure

AWS MFA Secure Session for CLI and SDK
Ruby
23
star
10

puma-cloudwatch

Puma plugin sends puma metrics to CloudWatch
Ruby
20
star
11

cody

Powerful DSL to easily create and manage AWS CodeBuild projects
Ruby
19
star
12

pipedream

Beautiful and Powerful DSL Tool to Easily Create AWS CodePipeline Pipelines Quickly
Ruby
14
star
13

terragrunt-vs-terraform-reusable-module

example terragrunt and terraspace projects to explain difference between reusable modules
HCL
10
star
14

jets-gems

Manages pre-compiled Lambda Gems for Jets Ruby Serverless Framework
Ruby
8
star
15

aws-logs

Tail AWS CloudWatch Logs
Ruby
7
star
16

sentry-jets

Sentry exception report support for Jets
Ruby
6
star
17

kustomize-examples

Kustomize Simple Examples: Multiple Environments like dev and prod
6
star
18

terraspace-graph-demo

Demonstrates how Terraspace is able to build the dependency graph and deploy multiple stacks at once
HCL
5
star
19

terraspace-dockerfiles

Terraspace Dockerfiles
Shell
4
star
20

jetpacker

jetpacker
Ruby
3
star
21

terraspace-bundler

Terraform bundler
Ruby
3
star
22

cli-format

Format cli output in different ways: tab, table, csv, json, etc
Ruby
3
star
23

kubectl-examples

Kubectl Kubernetes Examples
Shell
3
star
24

terraspace-demo-terrafile

Terraspace Terrafile Example Demo
HCL
2
star
25

terraspace-aws-vpc

Terraspace Project with Example AWS VPC
HCL
2
star
26

terraspace-azurerm-linux-vm

Terraspace project with example Azure Linux Virtual Machine
HCL
2
star
27

hcl_parser

HCL Parser
Ruby
2
star
28

helm-examples

Helm Kubernetes Examples
Smarty
2
star
29

homebrew-software

BoltOps Homebrew Software
Ruby
2
star
30

terraspace-docs

Terraspace Docs
JavaScript
2
star
31

terraspace-aws-eks

Terraspace project with example AWS EKS Cluster
HCL
2
star
32

rspec-terraspace

Terraspace RSpec support
Ruby
2
star
33

s3-secure

S3 Bucket security hardening tool
Ruby
2
star
34

terraspace-aws-iam

Terraspace project with example AWS IAM resources
HCL
2
star
35

kubes_aws

Kubes AWS Helpers Library
Ruby
2
star
36

terraspace-google-vm

Terraspace project with example Google VM
HCL
1
star
37

terraspace-aws-elb

Terraspace AWS ELB Example
HCL
1
star
38

kubes_google

Kubes Google Helpers Library
Ruby
1
star
39

cfn_response

CfnResponse makes it easier to build and send the CloudFormation Custom Resource response
Ruby
1
star
40

terraspace-aws-ec2

Terraspace project with example AWS EC2 Instance
HCL
1
star
41

jets-docs

Jets Docs
JavaScript
1
star
42

airbrake-jets

Airbrake exception report support for Jets
Ruby
1
star
43

azure_check

Check Azure access
Ruby
1
star
44

terraspace_plugin_aws

Terraspace AWS Provider
Ruby
1
star
45

terraspace-aws-rds

HCL
1
star
46

terraspace-azurerm-network

Terraspace project with example Azure network
HCL
1
star
47

terraspace-azurerm-aks

Terraspace project with example Azure AKS Kubernetes Cluster
HCL
1
star
48

serverlessgems

serverlessgems
Ruby
1
star
49

terraspace-demo-module-test

Terraspace module test demo
Ruby
1
star
50

terraspace-google-gke

Terraspace project with example Google GKE Kubernetes Cluster
HCL
1
star
51

terraspace_plugin_azurerm

Terraspace Azurerm Provider
Ruby
1
star
52

terraspace-aws-rds-aurora

Terraspace project with example AWS RDS Aurora Database
HCL
1
star
53

azure_info

Azure info: Simple library to get current subscription, resource group, and location, etc
Ruby
1
star
54

importmap-jets

JavaScript
1
star
55

terraspace-google-network

Terraspace project with Example Google Network
HCL
1
star
56

google_check

Simple script to check google access with GOOGLE_APPLICATION_CREDENTIALS
Ruby
1
star
57

terraform-workshop-aws

Simple Terraform Workshop for AWS
HCL
1
star
58

terraspace_plugin_google

Terraspace Google Cloud Provider
Ruby
1
star
59

terraspace-aws-security-group

Terraspace project with example AWS Security Group Module
HCL
1
star
60

terraform-aws-s3

Terraform s3 example module
HCL
1
star
61

glb

Ruby
1
star
62

google-ssl

Google Cloud Function SSL Cert Rotation Tool
Python
1
star
63

libcurl

Gem tells serverlessgems to build the gem package with libcurl
Ruby
1
star
64

terraspace-azurerm-windows-vm

Terraspace project with example Azure Windows Virtual Machine
HCL
1
star
65

armrest

Ruby
1
star