LoginSignup
0
1

More than 1 year has passed since last update.

RubyでServerless Frameworkを構築するための覚書

Posted at

Ruby使ってさっくりlambda functionのAPIを立ち上げるための覚書

準備

Serverless Framework のインストール

$ npm install -g serverless

テンプレートの展開

$ serverless create -t aws-ruby

rbenvを利用しているのでRubyのバージョンを指定

$ rbenv local 2.7.3

API Gatewayを生やしてHTTPリクエストを受け付けるように修正

# serverless.yml
functions:
  handler:
    handler: handler.webhook
    events:
      - httpApi:
          path: /webhook
          method: get

デプロイ

$ serverless deploy -v

環境変数

dotenv

開発をする上でdotenvを利用

step1: serverless-dotenv-pluginをインストール

$ npm i -D serverless-dotenv-plugin

.envファイルの修正

SAMPLE_ENV=hogehoge

serverless.ymlの修正

frameworkVersion: '2'

useDotenv: true

...

functions:
  webhook:
    handler: handler.hello
    events:
      - httpApi:
          path: /hello
          method: get
    environment:
      SAMPLE_ENV: ${env:SAMPLE_ENV}

参考

Building an API with Ruby and the Serverless Framework

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1