Home > Back-end >  Hold DynamoDB Stream Events in Lambda for a Small Period
Hold DynamoDB Stream Events in Lambda for a Small Period

Time:02-01

We're planning to add a few updates in Lambda Function which has been set as the trigger for DynamoDB New item Events

DynamoDB --> Event Bridge --> AWS Lambda

So while performing an update, we need to make sure no events should be received by lambda.

Are there any easy-to-implement methods to do this??

CodePudding user response:

First of all why are you using EventBridge?

The path should be DynamoDB -> DynamoDB Streams -> Lambda.

To ensure the Lambda only receives new items you can use a Lambda Event Filter

{
  "filters": [
    {
      "pattern": "{\"eventName\" : [\"INSERT\"] }"
    }
  ]
}

CodePudding user response:

Option 1: Streams -> Lambda (with enable/disable)

DynamoDB Streams can send events directly to Lambda using the Event Source Mapping integration. An Event Source Mapping is an AWS-managed poller resource that pulls events for you. If you remove EventBridge from the equation and use an Event Source Mapping, you can pause the flow of messages to the Lambda consumer with its enabled property:

docs: Set to true to enable the event source mapping. Set to false to stop processing records. Lambda keeps track of the last record processed and resumes processing from that point when the mapping is reenabled.

The UpdateEventSourceMapping API sets the enabled property:

aws lambda update-event-source-mapping --uuid <mapping-uuid> --enabled false

Option 2: Streams -> EventBridge -> Lambda (with archive and replay)

If you really need the EventBridge integration, you can temporarily disable the rule that triggers your Lambda, then use the EventBridge archive and replay functionality to catch up when ready. You take responsibility for determining which events need reprocessing. This will be easier if your application is idempotent.

  • Related