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
답변함 일 년 전
profile pictureAWS
전문가
kentrad
검토됨 일 년 전
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
답변함 일 년 전
profile pictureAWS
전문가
검토됨 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠