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 年前檢視次數 780 次
2 個答案
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 pictureAWS
專家
已回答 2 年前
profile pictureAWS
專家
Chris_G
已審閱 2 年前
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 pictureAWS
專家
Uri
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南