Code Monkey home page Code Monkey logo

rumbda's Introduction

rumbda Build Status Gem Version

Run ruby scripts on aws lambda.

Installation

gem install rumbda

or add it to the Gemfile

group :development do
  gem 'rumbda'
end

What does rumbda do?

Rumbda does everything necessary to build a zip file for running ruby inside of an AWS Lambda. This includes downloading traveling ruby, creating a bundle of the project's Gemfile dependencies, and creating a consumable .zip file for use with Lambda.

Getting Started

Run rumbda init in the directory you'd like to have your Lambda project. This will create the following files in the current directory: source/main.rb, Gemfile, .gitignore, and .ruby-version. source/main.rb is the entry point to the ruby script. The Gemfile and Gemfile.lock are where gems are specified.

Building the zip

rumbda build
# => creates a file "index.zip" which contains all files in "source/" and all gems specified in the "Gemfile"

Configuring the Lambda

  1. Set Runtime to Node.js 6.10.

    node_js_version.png
  2. Set Code entry type to Upload a .ZIP file.

    images/code_entry_type.png
  3. In the Function package upload index.zip (the zip created by rumbda build).

    select_index_zip.png
  4. Set Handler to index.handler.

    handler.png

Example

See the example folder for what a project using rumbda might look like.

pwd
#=> ~/rumbda/example
ruby --version
#=> 2.2.2
bundle install
#=> installs dependencies, creates Gemfile.lock
bundle exec rumbda build
#=> builds the index.zip file

After the index.zip file is built, follow the steps for Configuring the Lambda.

Environment Variables and Events

Lambda environment variables are available to main.rb via ENV['<variable name>']. See the example.

The Lambda Event is available to the script via ARGV[0]. See the example. If testing the script locally, simply pass in a json as the first argument to the script:

$ ruby main.rb "$(cat test_event.json)"

Return JSON for API Gateway

If needing to return JSON from your lambda (e.g. for use in AWS API Gateway) write to a file path provided in your lambda's environment at key 'RUMBDA_RESULT_JSON_FILENAME'.

File.open(ENV['RUMBDA_RESULT_JSON_FILENAME'], 'w') do |file|
  file.write(JSON.dump({ statusCode: 200, body: '' }))
end

The file contents should be valid JSON.

Command Reference

Command Purpose
rumbda init Initializes a directory as rumbda project.
rumbda build Packages everything in ./source/ directory as well as gems specified in the Gemfile into a zip file called index.zip

rumbda's People

Contributors

bradleyjames avatar

Watchers

 avatar  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.