LoginSignup
3
1

More than 3 years have passed since last update.

Serverless Frameworkでevent scheduleをステージ毎に切り替える

Last updated at Posted at 2019-11-26

環境

  • Serverless Framework

やりたいこと

CloudWatch Eventの定期実行をステージングでは手動実行、本番では定期実行させたいということがあったので、備忘録として残しておきます。

serverless.yml

至って簡単です。


service: hoge

provider:
  name: aws
  runtime: nodejs8.10
  stage: ${opt:stage, self:custom.defaultStage}
  region: ap-northeast-1

custom:
  defaultStage: dev
  schedule_active:
    dev: "false"
    prod: "true"
    default: "false"

functions:
  hello:
    handler: handler.hello
    events:
      - schedule:
        rate: rate(30 minutes)
        enabled: ${self:custom.schedule_active.${opt:stage, self:custom.defaultStage}, self:custom.schedule_active.default}

上記で通常はscheduleを実行しないで、prod環境の時だけ、定期実行を行うように出来ます。
sls deploy --stage prod でデプロイすればOK

3
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
3
1