Skip to content
Simple Rails & AWS Lambda Integration using Rack πŸš‚πŸ‘
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
doc [DONE] Ensure Rack integration is solid and high quality. Mar 21, 2019
lib Prepare for v0.2.0 Mar 13, 2019
test
.gitignore Initial project code & docs. Mar 13, 2019
.python-version
.ruby-version
.travis.yml πŸ‘· Use bin/setup and bin/test in Travis Mar 14, 2019
Brewfile
CHANGELOG.md
CODE_OF_CONDUCT.md Initial gem structure via Bundle gem. Mar 10, 2019
Gemfile Prepare for v0.1.0. Mar 10, 2019
Gemfile.lock
LICENSE.txt Initial gem structure via Bundle gem. Mar 10, 2019
Pipfile
Pipfile.lock πŸ‘’ Add bin/bootstrap script Mar 14, 2019
README.md
Rakefile Initial gem structure via Bundle gem. Mar 10, 2019
lamby.gemspec Initial project code & docs. Mar 13, 2019

README.md

Lamby Build Status

Lamby: Simple Rails & AWS Lambda Integration using Rack.

Simple Rails & AWS Lambda Integration using Rack

The goal of this project is to provide minimal code to convert API Gateway event and context objects into Rack events for your Rails application in a Lambda handler. Most everything else is documentation.

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

Getting Started

Add The Gem

Add the Lamby gem to your Rails project's Gemfile.

gem 'lamby'

Create Handler

Create an app.rb file that will be the source for the Lambda's handler. Example:

ENV['SECRET_KEY_BASE'] = '...' # Temporary hack, see TODO list in projects tab.
require_relative 'config/boot'
require 'lamby'
require_relative 'config/application'
require_relative 'config/environment'

$app = Rack::Builder.new { run Rails.application }.to_app

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

Create SAM Template

Create an AWS SAM template.yaml file that expresses your function's resources and how it receives events from API Gateway. Please use this full doc/template.yaml file hosted here as a starting point. The basic template accomplishes the following.

  • Defines a RailsEnv input parameter.
    • Applies this to the RAILS_ENV environment variable.
  • Creates a API Gateway resource named RailsApi.
    • Ensures that the stage name is set to the Rails env.
    • Using inline Swagger, define a root / via GET and greedy proxy /{resource+} via ANY.
    • Allow any binary media type to be a valid response.
  • Creates a Lambda function resource named RailsFunction.
    • Sets the handler to app.handler. File above.
    • Defines events from API above for both root and greedy proxy.
  • Simple Outputs that echos the resources you created.

Git Ignores

Ensure both /.aws-sam and /vendor/bundle are added to .gitignore. AWS SAM uses the .aws-sam directory to build your project. No file there should be committed to source control.

$ echo '/.aws-sam' >> .gitignore
$ echo '/vendor/bundle' >> .gitignore

Get Running

To run your Lambda locally or deploy it, please read the following docs.

Additional Documentation

In order to provide minimal code and ultimate flexibility for any type of Rails application on Lambda, optional or advanced features require that you write additional CloudFormation code or perform AWS Console actions to get the desired results.

To that end, we are using our GitHub issues along with the [docs] label as a project-focused Stack Overflow where we encourage you to participate in and ask questions. Here are a few high level docs now that may interests most users. Also, browse all docs or open a new [question] issue and we would be glad to help!

About AWS SAM and CloudFormation

AWS SAM is shorthand for the Serverless Application Model and it is a superset of CloudFormation - a language that describes and provisions your infrastructure using code. As your application grows and requires additional AWS resources, learning how to express this in your template.yaml is critical. We recommend the following links when needing to learn both SAM and CloudFormation.

Contributing

After checking out the repo, run ./bin/setup to install dependencies. Then, run ./bin/test to run the tests. NOTE: There are no tests now but adding them is on our TODO list.

Bug reports and pull requests are welcome on GitHub at https://github.com/customink/lamby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Code of Conduct

Everyone interacting in the Lamby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

You can’t perform that action at this time.