1

以下のブロックをserverless.ymlファイルに追加して、CRON をスケジュールしました。

testCron1:
    handler: handler.testCron1
    events:
      - schedule: cron(15 14 22 MAY FRI 2020)

次に、ファイルにtestCron1ラムダ関数を作成しhandle.jsます。

const testCron1 = (event, context) => {
    return new Promise(async (resolve, reject) => {
        console.log("*********** NEW est CRON ************");
        console.log("Current Time ==> ", new Date(moment().utc().format()));
        resolve(true);
    });
}

command を使用してデプロイしようとするとserverless deploy、以下のエラーが表示されます。

An error occurred: TestCron1EventsRuleSchedule1 - Parameter ScheduleExpression is not valid. (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code:ValidationException; Request ID: c5b3178b-348a-4ffd-a205-d5255dcca2ab)
4

1 に答える 1

1

ラムダを使用している場合は、クラウド ウォッチを cron トリガーとして使用します。

クラウド ウォッチを使用して、特定の時間にラムダ関数のトリガーを処理するのは簡単です。

ここでトリガールール式を見つけることができます: https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html

ここで確認できるサポートされている値のリスト: https://docs.aws.amazon.com/systems-manager/latest/userguide/reference-cron-and-rate-expressions.html

Example cron : 0 11 17 4 ? 2020 min hours day month dayOfWeek year

This will execute once on FRI, 17 APR 2020 11:00:00 GMT as an example.
于 2020-05-22T15:48:06.783 に答える