Amplify Function 定期実行(cron式)の設定でつまずいた時の対応

技術メモ

Amplify CLIでLambda が1時間毎に実行されるよう設定しようとしました。

しかし、cron式定期実行の設定のところで怒られてしまいした。

% amplify update function
? Select which capability you want to update: Lambda function (serverless function)
? Select the Lambda function you want to update pushPhrase

? Which setting do you want to update? Scheduled recurring invocation
? Do you want to update or remove the function's schedule? Yes
? Select from the following options: Update the schedule
? At which interval should the function be invoked: Custom AWS cron expression
? Custom Schedule expression(Learn more: https://amzn.to/3akXtJF) 0 */1 * * * *
>> Enter a valid Schedule Expression (Learn more: https://amzn.to/3akXtJF)

下のような書き方だとダメみたいです。

0 */1 * * * *

AWS公式ドキュメントを参照したところ、cron式の左から五番目(曜日フィールド)にはワイルドカード(*)を設定できないと書いてありました。

ワイルドカード * (アスタリスク) にはフィールドのすべての値が含まれます。時間フィールドの、* にはすべての時間が含まれています。[*] を日および曜日フィールドの両方に使用することはできません。一方に使用する場合は、もう一方に [?] を使用する必要があります。

ドキュメントの言うとおり左から五番目に「*」ではなく「?」 を設定したらいけました。

0 */1 * * ? *

修正後↓

% amplify update function
? Select which capability you want to update: Lambda function (serverless function)
? Select the Lambda function you want to update pushPhrase

? Which setting do you want to update? Scheduled recurring invocation
? Do you want to update or remove the function's schedule? Yes
? Select from the following options: Update the schedule
? At which interval should the function be invoked: Custom AWS cron expression
? Custom Schedule expression(Learn more: https://amzn.to/3akXtJF) 0 */1 * * ? *
? Do you want to edit the local lambda function now? Yes

あとがき

ちなみに下のように6つの値以外の文字を入れてもエラーになります。cron()はいらないみたいです。

cron(0 */1 * * ? *)

コメント

タイトルとURLをコピーしました