How to set up Eventbridge with on-demand service request

0

Hello,

After doing some research, I found that EventBridge can do cron jobs task but I wasn't sure what the best way to solve my issue. My service is an on-demand service which customer post a question and the request is stored in dynamoDB with the current start time, I want to create a event that trigger 5 minutes after user request is saved to dynamodb, and call a lambda function. I don't want to manually go into Event bridge to create the event, it should be automate so that every time user posts a question, then 5 minute later it will trigger a lambda function. This doesn't have to be recurring event, it just need to be triggered 5 minute after the request is added to dynamodb. Please advise.

2 Answers
0
  1. You can use DynamoDB Streams to trigger a lambda function - https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.Lambda.html https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html

  2. It is not advisable to sleep inside of a lambda function. Instead you could invoke a Step Function from within the lambda function - https://docs.aws.amazon.com/step-functions/latest/dg/concepts-invoke-sfn.html

  3. to use the Wait Task to sleep for 5 minutes - https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-wait-state.html

  4. Finally, after the sleep, you can invoke another lambda function from the Step Function that will trigger off whatever you want to do after the 5 minute sleep - https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-task-state.html

Note that in Step 1, it is possible for multiple records to be delivered by DynamoDB streams to your lambda function as an array of records, so you can invoke one instance of the step function state machine for each record

profile picture
EXPERT
answered 3 months ago
profile picture
MODERATOR
Chris_G
reviewed 3 months ago
0

EvenBridge cron are used for recurring events. Not for one time tasks. What you should do is setup a DynamoDB stream, attach it to a Lambda function. The Lambda function will send a message to an SQS Delay queue. The queue will trigger a second function that will perform the task.

If you want to eliminate the use of the first function and the DynamoDB stream, you can have the application that writes to DynamoDB to send the message to the Delay queue directly.

profile picture
EXPERT
Uri
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions