Invoke AWS Lambda function only once, at a single specified future time

Ethan Harlig picture Ethan Harlig · Dec 19, 2017 · Viewed 9.9k times · Source

I want to be able to set a time to invoke an AWS Lambda function, then have that function be invoked then and only then. For example, I want my Lambda function to run at 9:00pm on December 19th, 2017. I don't want it to repeat, I don't want it to invoke now, just at 9:00pm on the 19th.

I understand that CloudWatch provides Scheduled Events, and I was thinking that when a time to schedule this reminder for is inputted, a CloudWatch Scheduled Events is created to fire in that amount of time from now (so like if you schedule it at 8:22pm to run at 9pm, it’ll be 38 mins), then it invokes the Lambda function at 9pm which then deletes the CloudWatch Scheduled Event. My issue with this is that when a CloudWatch Scheduled Event is created, it executes right then, then at the specified interval.

Any other ideas would be appreciated, as I can't think of another solution. Thanks in advance!

Answer

Kush Vyas picture Kush Vyas · Dec 19, 2017

You can schedule lambda event using following syntax:

cron(Minutes Hours Day-of-month Month Day-of-week Year)

Note: All fields are required and time zone is UTC only

Please refer this AWS Documentation for Details.

Thanks