0

I am trying to setup a cloudwatch rule to trigger a lambda based on this doc: https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html.

What I'd like to do is to trigger a lambda at every 3rd second per 5 minutes. For example, I want to trigger it as:

00:00:03
00:05:03
00:10:03
...

but I can't find a solution to configure second level in the cron expression. Is there any solution to that?

Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523

2 Answers2

2

Cron only allows for a minimum of one minute. So configuration of second is not possible with cron expression. You can take hybrid approach by executing your lambda function at every 5 minutes and handle the 3rd second logic in your function by writing sleep function.

import time
def lambda_handler():
    time.sleep(3)
    # Now execute your logic
Gunjan
  • 986
  • 9
  • 10
1

I think timing to second level is near impossible. possibly it can be adjusted to following

  1. initiate every minute via Cron expression.
  2. defer execution of processing logic using sleep for (1-3 seconds) if second portion of current time is under 3 second.
  3. Skip entire processing logic if at the initiation time if second portion of the current time is above some high number of seconds like 5x if that suits the need. 59 will mean no-skip.
RSA
  • 26
  • 4