GithubHelp home page GithubHelp logo

jmitchtx / lamby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rails-lambda/lamby

1.0 2.0 0.0 57 KB

Simple Rails & AWS Lambda Integration using Rack πŸš‚πŸ‘

Home Page: https://lamby.metademo.net

License: MIT License

Ruby 94.18% Shell 5.82%

lamby's Introduction

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. Recommend only requiring Lamby in your app.rb so your local development or test logs still work.

gem 'lamby', require: false

Create Handler

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

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!

Local AWS Dependencies

Other Guides Just For You!

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.

lamby's People

Contributors

metaskills avatar rypit avatar zachallett avatar

Stargazers

Matthew Russell Dodds avatar

Watchers

James Mitchell avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.