How to schedule AWS Lambda to run exactly at 12:00:00 am (second-level precision)?

Viewed 1654

I have a use case where I need to run a function daily at 12:00:00 am. My Python code takes 3-4 seconds to initialize and 3 seconds to execute. It would still be fine if my function is triggered within 1 second after 12:00:00 am, but I can't do it with AWS Lambda triggered by AWS CloudWatch.

I have created a AWS Lambda function and it's being triggered every 11:59 pm using AWS CloudWatch Events because it does not provide second level precision. So, it's wasting computing time averaging between 15 - 45 seconds after initializing just to sleep until 12:00:00 am.

Although the price is still quite low, but I just felt annoyed that the majority (>75%) of the computing time taken is used to Sleep. Anyone else has a better idea?

1 Answers

Have you tried scheduling lambda execution using cron expression?

This expression 0 0 * * ? * would run your lambda every day at midnight GMT. Adjust accordingly to your time zone.

scheduling lambda with cron expression

Related