Install Lamby

We need to bundle the Lamby gem to your Rails project's Gemfile. We use the require: false option so Lamby is only loaded in your app.rb, more info on that file later. Not requiring Lamby helps keep your local development working normally. For example, your logs still writing to disk vs. using STDOUT.

gem 'lamby', require: false
gem 'aws-sdk-ssm'

Install Lamby's Files

Lamby provides a simple Rake task to install the files needed for AWS Lambda to run your application. In this example, we are using the default Application Load Balancer installer but ApiGateway is supported too by using the lamby:install:api_gateway task instead.

$ ./bin/rake -r lamby lamby:install

This will install the following files. We will cover each in more detail later.


Think of the app.rb file the same way Rails has a except for Lambda to run your Rails/Rack app. This file should remain relatively simple and do the following:

require_relative 'config/boot'
require 'lamby'
require_relative 'config/application'
require_relative 'config/environment'

$app = { run Rails.application }.to_app

def handler(event:, context:)
  Lamby.handler $app, event, context, rack: :alb

Lamby does all the work to convert the event and context objects it Rack messages that get sent to your Rails application. The details of the AWS Lambda Function Handler in Ruby should be left to Lamby, but please learn about this topic if you are interested.

Lamby 🆕 Application Load Balancer ALB Support     GitHub