DEV Community

Cover image for Building AWS Lambdas for Real World using Ruby and Serverless Framework

Building AWS Lambdas for Real World using Ruby and Serverless Framework

Jalerson Lima on December 09, 2018

You may be wondering: "Why AWS Lambdas for Real World?". Well, since Amazon announced Ruby support for AWS Lambdas on November 29th, I've been read...
Collapse
 
joshuaflanagan profile image
Joshua Flanagan

I just published a serverless plugin to handle a lot of this npmjs.com/package/serverless-ruby-...

The are a couple modifications from the approach you describe. First, the plugin excludes all files by default, so you need to whitelist (add to the package/includes section) any files or directories you want to package.
Second, I recommend bundle install --standalone --path vendor/bundle instead of messing with bundle install --deployment. As you discovered, the "deployment" mode is really only intended for deployment, not active development, so you always need to immediately undo it. Instead, "standalone" accomplishes the part we actually care about, specifically, it copies all of the gem files into the vendor directory in your working directory. The plugin then analyzes your Gemfile to figure out which gems should be included, or excluded if they are in the development/test groups.

Collapse
 
rodg_co profile image
Rodrigo Garcia Couto • Edited

I've managed my deployment pipeline in a different way, using the serverless-hooks-plugin and adding the following to the serverless.yml:

plugins:
  - serverless-hooks-plugin

custom:
  hooks:
    package:initialize:
      - bundle install --path vendor/bundle --without test development --clean
      - rm -rf ./vendor/bundle/ruby/2.5.0/cache

    package:finalize:
      - bundle install --path vendor/bundle --with test development --clean
Collapse
 
etiennedepaulis profile image
Etienne Depaulis

Great article Jalerson ! I published an article on the same topic this morning : medium.com/lifen-engineering/circl...

Collapse
 
annarankin profile image
Anna Rankin

This is great! Thanks so much for the overview of the process and pitfalls; can't wait to try this out.

Collapse
 
ben profile image
Ben Halpern

Auto-bookmark! Can't wait to see more of what Rubyists do with Lambda.

Collapse
 
cads profile image
Carlos Donderis

Did you manage to install gems that have native bindings (such as mysql2) successfully?

Collapse
 
mrjasonroy profile image
Jason Roy

This is super helpful! I am having issues with conflicting gems already installed on lambda and being preferred (specifically, JSON 2.1.0 is too new). Did you find anything like that?