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}