$30 off During Our Annual Pro Sale. View Details »

Building Ruby Bots on AWS Lambda

DamirSvrtan
February 21, 2017

Building Ruby Bots on AWS Lambda

Want to build a Ruby Bot without the hassle of provisioning and managing servers? Amazon's got a service for that and it's called AWS Lambda - it executes your code only when needed, scales automatically and you pay only for the compute time you consume.

There's one problem with Lambda - it doesn't support Ruby!
Let's checkout multiple options on how to build a Ruby Bot and package it into an executable which you can run on any machine without the need to actually have Ruby installed.

DamirSvrtan

February 21, 2017
Tweet

More Decks by DamirSvrtan

Other Decks in Programming

Transcript

  1. 1. Download the Android apk file. 2. Decompile the apk

    file 3. Reverse engineer the code.
  2. 1. Install the iOS app 2. Plug my mobile to

    a computer 3. Use Charles to sniff traffic
  3. # main.rb require 'net/http' require 'time' class ApartmentPublishDates LAST_SCRAPPED_AT =

    Time.now - 1 * 60 # 1 minute ago. attr_reader :url def initialize(url) @url = url end def all response_body .scan(/datetime\="(.*)" /) .map(&:first) .map { |time| Time.parse(time) } end def recent all.select { |publish_date| publish_date > LAST_SCRAPPED_AT } end private def response_body Net::HTTP.get(URI(url)) end end
  4. Download the runtimes OS X for our dev machine Linux

    x86_64 compatible binary for AWS Lambda
  5. traveling-ruby-bot - ruby-linux-x86_64 - bin/ - ruby - ... -

    ... - ruby-os-x - bin/ - ruby - ... - ...
  6. // lambda-function-wrapper.js var spawn = require('child_process').spawn; exports.handler = function(event, context)

    { var child = spawn('ruby-linux-x86_64/bin/ruby main.rb'); child.stdout.on('data', function (data) { console.log("stdout:\n"+data); }); child.stderr.on('data', function (data) { console.log("stderr:\n"+data); }); child.on('close', function (code) { context.done(); }); }
  7. Good Traveling Ruby Tutorials hello world app app with gems

    app with native extensions such as Nokogiri
  8. Two ways to build apps with MRuby: - download mruby

    source directly from Github - mruby-cli - platform for building native command line applications for Linux, Windows, and OS X.
  9. AWS Lambda Pricing the number of requests (i.e. number of

    times our function is invoked) the sum of durations our functions took to execute (expressed in GB-seconds)