3
0

More than 1 year has passed since last update.

AWS SAM cron 設定は UTC 依存ではなく Timezone 依存のスケジューラ (ScheduleV2) を使おう

Posted at

背景

Lambda の定周期稼働方法を探すと、普通に以下が見つかるが・・

よっしゃと思い設定してみると、設定時刻通りに動かない。
そう、よくある UTC 問題

image.png

その後、途中諦めかけていたが、Console 側に Timezone 設定可能なスケジューラというものを見つけて、そこからドキュメント経由で ScheduleV2 を見つけたので紹介。

結論:Local Zone で動く Scheduler

Scheduler なら、TimeZone 由来で動かせるのです。
image.png

設定方法

Type: Schedule (V1) だと、Schedule: で設定してたのが、ScheduleExpression: になってたり、ScheduleExpressionTimezone 設定しないと Default の UTC になるのでご注意を

トリガー設定例
        ScheduleV2Event:
          Type: ScheduleV2
          Properties:
            Name: ScheduleV2EveryTueSat2120
            ScheduleExpression: cron(20 12 ? * TUE,SAT *)
            Description: Example schedule2
            ScheduleExpressionTimezone: "Asia/Tokyo"

で、sam deploy すると、こんな感じで設定出来てることが分かる
image.png

ただ・・ Lambda 側からは、現状 Scheduler は見られないみたい・・ 2022/12/4 現在

関連ドキュメント

各 Property は、以下で調べられる

TimeZone はここ

EventBridge スケジュールの information から飛んでく説明ページが以下(これのおかげで見つけられました)

Console で設定する場合

image.png

但し、ここから Lambda への接続は可能ですが、Lambda 側からは表示できません。
故に、Lambda からスケジュールへの接続は、2022/12/4 時点では選べないので注意。
※設定は出来てそう

あとがき

はやく以下を対応してほしい限り

  • 日本語訳
  • Lambda 側での Console での設定

keyword

Use EventBridge Scheduler rather than Rule if you want to set in TimeZone not UTC.

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