EventBridge(Cloudwatch 触发器)启用后每 5 分钟 Cron 表达式 Aws 到 运行

Cron expression Aws to run every 5 minutes after EventBridge (Cloudwatch trigger) enables

我见过几个例子,它们都在特定时间触发一个工作,我现在有: 0 */5 * ? * * 它在第 0、5、10 分钟等处触发。 但是,我需要在启用触发器的那一刻的 +5 时将触发器设为 运行。

因此,如果服务在 12:07 下午启用,我需要它 运行 然后在 12:12 下午等等。 有办法实现吗?

正如您提到的,偏移量是解决您问题的一部分。

0 */5+your_offset * ? * *

现在来看看你的偏移量:

假设 cloudwatch-event 网桥在某些 12:07 启用(您可以从事件详细信息时间戳中获取该信息。)

your_offset = 7 + 5
// so your cron becomes :  0 */5+12 * ? * *

或者一般来说你的

offset = the minute part of timestamp + 5 
// for your to schedule 5 mins after service is enabled

解决方法很简单:

在创建规则之前检查当时的分钟时间

time_minutes_now */5 * ? * *