Invoking Lambda when record inserted to dynamoDB

2.2k Views Asked by At

Need to invoke lambda when record inserted to dynamoDB table, But here i need to invoke lambda after 60 seconds of record insertion, is there any way that invoke lambda after n seconds?

3

There are 3 best solutions below

0
On BEST ANSWER

To solve this in a "scalable" manner I would use the following AWS products:

  1. DynamoDB Streams
  2. EventBridge
  3. Step Function

The process would look like this:

  1. As soon as your first Lambda inserts a new entry in your table, DynamoDB streams will be "triggered".
  2. You configure a Lambda to "listen" to the stream events.
  3. This Lambda should then put an event onto EventBridge. You do this instead of directly doing something here, because according to documentation, you should only have a maximum of two Lambdas "listening" on stream events. Therefore, I would recommend sending those "events" to EventBridge, so that you can add more/other processing steps to your DynamoDB streams. But this is optional.
  4. You create a rule in EventBridge that would trigger a Step Function with the appropriate payload (for example the DynamoDB keys you want to work on).
  5. The Step Function (as Artem described) could then contain a step that waits for n seconds, before another Lambda is triggered to run your code.
0
On

You could trigger a lambda that writes your DynamoDB events to a SQS Queue, which is getting polled by your initial lambda. Then you could customize the polling intervall and therefore the duration your lambda gets invoked after something was inserted into the table.

0
On

You can achieve such behavior with AWS StepFunctions. There is a special "wait" state, which is used to delay before next step.

So the idea is that state machine is launched in response to a new DynamoDB record, then it transits to the "wait" step (60 sec) and then transits to a "task" step with your lambda function.