cron every 2 minutes with lambda function

0

Hi all, I have a lambda function that i need to run every two minutes, i am just using the AWS interface, not using Serverless.

Via EventBridge, i have defined the following trigger with cron: */2 * * * ? *

This does not work as expected, the function runs sporadically every hour or so at odd times.

The EventBridge console shows a correct schedule:

  • Thu, 30 Mar 2023 09:32:00 UTC
  • Thu, 30 Mar 2023 09:34:00 UTC
  • Thu, 30 Mar 2023 09:36:00 UTC
  • Thu, 30 Mar 2023 09:38:00 UTC
  • Thu, 30 Mar 2023 09:40:00 UTC
  • Thu, 30 Mar 2023 09:42:00 UTC
  • Thu, 30 Mar 2023 09:44:00 UTC

but on CloudWatch monitor i see the function is not running as expected:

  • 2023-03-30 12:06:15 (UTC+03:00)
  • 2023-03-30 11:54:15 (UTC+03:00)
  • 2023-03-30 09:38:40 (UTC+03:00)
  • 2023-03-30 09:38:14 (UTC+03:00)
  • 2023-03-30 07:38:15 (UTC+03:00)
  • 2023-03-30 05:12:15 (UTC+03:00)
  • 2023-03-30 03:11:17 (UTC+03:00)

Any help would be appreciated, thank you

2 回答
0

Hi, I believe the leading * means every hour, so I'm not sure how */2 is interpreted. If you want every 2 minutes, I think you should write 0/2. That's what I'm using for my own event: 0/5 triggers my lambda every 5 minutes.

See example here (https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html): Run every 10 minutes is 0/10 and Run every 15 minutes is 0/15.

profile pictureAWS
Jsc
已回答 1 年前
profile pictureAWS
专家
kentrad
已审核 1 年前
0

If you need something to run every two minutes, and you don't care when it starts, you can just use a rate schedule and indicate rate (2 minutes).

Also, you should probably use the new EventBridge scheduler instead of the scheduling rules.

profile pictureAWS
专家
Uri
已回答 1 年前
profile pictureAWS
专家
已审核 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则