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 Respostas
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
respondido há um ano
profile pictureAWS
ESPECIALISTA
kentrad
avaliado há um ano
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
ESPECIALISTA
Uri
respondido há um ano
profile pictureAWS
ESPECIALISTA
avaliado há um ano

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas