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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ