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回答
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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ