Jets ~ Rubyで始めるServerless生活 ~

Jets ~ Rubyで始めるServerless生活 ~

AWSのLambda上でRubyを使ってサーバレスアプリを作成・運用することが出来るフレームワーク「Jets」の紹介です。

19675bc717632ffd7c53aa8b9a9c3cbf?s=128

Hirokatsu Endo

November 28, 2019
Tweet

Transcript

  1. 19.

    class PostsController < ApplicationController def index # renders Lambda Proxy

    structure compatible with # API Gateway render json: {hello: "world", action: "index"} end def show # params available id = params[:id] # puts goes to the lambda logs puts event # raw lambda event available render json: {action: "show", id: id} end … end
  2. 20.
  3. 21.

    Jets.application.routes.draw do get "posts", to: "posts#index" get “posts/new", to: "posts#new"

    get “posts/:id", to: "posts#show" post "posts", to: "posts#create" get "posts/:id/edit", to: "posts#edit" put "posts", to: "posts#update" delete “posts", to: "posts#delete" # expands to the RESTful routes above resources :posts # GET, POST, PUT, etc request all work any "posts/hot", to: “posts#hot” … end
  4. 22.
  5. 23.

    class HardJob < ApplicationJob rate "10 hours" # every 10

    hours def dig puts "done digging" end cron "0 */12 * * ? *" # every 12 hours def lift puts "done lifting" end … end
  6. 27.

    class ThermostatJob < ApplicationJob iot_event "SELECT * FROM 'my/topic'" def

    measure puts "event #{JSON.dump(event)}" end … end
  7. 29.

    class DataJob < ApplicationJob kinesis_event "my-stream" def file puts "event

    #{JSON.dump(event)}" puts "kinesis_data #{JSON.dump(kinesis_data)}" end … end
  8. 35.

    $ jets deploy Deploying to Lambda demo-dev environment... => Copying

    current project directory to temporary build area: /tmp/ jets/demo/app_root => Setting up a vendored copy of ruby. => Replacing compiled gems with AWS Lambda Linux compiled versions. Deploying CloudFormation stack with jets app! Uploading /tmp/jets/demo/code/code-7169d0ac.zip (88.8 MB) to S3 Time to upload code to s3: 1s 02:08:20AM UPDATE_IN_PROGRESS AWS::CloudFormation::Stack demo-dev User Initiated ... 02:08:48AM CREATE_IN_PROGRESS AWS::CloudFormation::Stack PostsController 02:10:03AM UPDATE_COMPLETE AWS::CloudFormation::Stack demo-dev Stack success status: UPDATE_COMPLETE Time took for stack deployment: 1m 46s. Prewarming application... API Gateway Endpoint: https://xxxxxxxxxx.execute-api.us- west-2.amazonaws.com/dev/
  9. 41.

    class PostsController < ApplicationController def index # renders Lambda Proxy

    structure compatible with # API Gateway render json: {hello: "world", action: "index"} end def show # params available id = params[:id] # puts goes to the lambda logs puts event # raw lambda event available render json: {action: "show", id: id} end … end
  10. 42.
  11. 44.

    Jets.application.routes.draw do get "posts", to: "posts#index" get “posts/new", to: "posts#new"

    get “posts/:id", to: "posts#show" post "posts", to: "posts#create" get "posts/:id/edit", to: "posts#edit" put "posts", to: "posts#update" delete “posts", to: "posts#delete" … end
  12. 45.
  13. 47.

    class HardJob < ApplicationJob rate "10 hours" # every 10

    hours def dig puts "done digging" end … end
  14. 48.
  15. 54.
  16. 56.