moataz omar
moataz omar

Reputation: 1

Trigger execution of a AWS lambda function at a specific time depending on code logic

I have a question related to AWS on how to trigger a Lambda function based on time. I have a booking system where users can book a ride. I want to send an automated notification for them e.g. 10 mins from the time rider should arrive in case the rider is late. How can I trigger the lambda function to run (as an example 02:30 and the current time is 12:00)

Upvotes: 0

Views: 170

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269284

Presumably you could have hundreds of users who need to receive notifications at any particular time. Therefore, merely triggering the Lambda function at a particular time probably isn't the way to accomplish this.

Instead, you could:

  • Use a database to maintain the times that users should be notified
  • Trigger an AWS Lambda function every minute
  • The Lambda function would:
    • Consult the database to find any notification that is due to be sent now (or previously) and has not already been sent
    • Send the notification
    • Mark the notification as sent (or delete it from the database)

Note that the function should look for any notification that is due, even if it was for a previous time. This will handle situations where notifications were not successfully sent previously, or where the Lambda function doesn't run for some reason.

The Lambda function can be triggered on a schedule by using Amazon CloudWatch Events.

Upvotes: 4

Related Questions