1

我在文件中添加了以下块serverless.yml来安排 CRON:

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

然后我在文件中创建一个testCron1lambda 函数。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);
    });
}

当我尝试使用命令进行部署时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

如果您使用 lambda,请使用 cloud watch 作为 cron 触发器。

使用 Cloud Watch 在特定时间处理 lambda 函数触发器会很容易。

您可以在此处找到触发规则表达式: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 回答