C.Lee
C.Lee

Reputation: 11279

Configure DynamoDB stream trigger with insert only

I currently have an AWS DynamoDB stream triggers a Lambda function.

The Lambda function is triggered by both insert and update events in the DynamoDB. Is there a way to change the configuration so that the Lambda function would only be triggered by 'insert'?

Upvotes: 15

Views: 13033

Answers (5)

Sebastian Sippl
Sebastian Sippl

Reputation: 11

You can use stream filters now and filter for those event types that you need only:

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.Lambda.Tutorial2.html

Upvotes: 1

ALFmachine
ALFmachine

Reputation: 808

While the accepted answer was accurate this is now supported by Lambda Event Filtering leveraging event source mappings.

aws lambda create-event-source-mapping \
    --function-name my-function \
    --event-source-arn arn:aws:sqs:us-east-2:123456789012:my-queue \
    --filter-criteria "{\"Filters\": [{\"Pattern\": \"{ \"a\" : [ 1, 2 ]}\"}]}"

Furthermore, you can include this in your Cloud formation or CDK workflow. See the accepted answer from this for more details.

Upvotes: 3

Andrey Borisko
Andrey Borisko

Reputation: 4609

In general, not only for nodejs but all types, this is supported for non global tables. Good collection of filter snippets can found here.

You basically apply filtering on Lambda service side before function gets triggered.

PS, Also great article explaining how it works

Upvotes: 0

Pirate
Pirate

Reputation: 101

You can use your lambda function to ignore rest other than insert.

 for record in event.get('Records'):
    if record.get('eventName') in ('INSERT'):
       """ code for execution. """

    elif record.get('eventName') == 'REMOVE':
        pass
    elif record.get('eventName') ==  'MODIFY':
        pass

Upvotes: 7

Peter Fennema
Peter Fennema

Reputation: 1690

To my knowledge this is not possible. AWS Lambda polls the stream and invokes your Lambda function when it detects any type of stream record update. Your Lambda will have to ignore the records that you are not interested in. You can use the eventName property of the stream record (can have values INSERT | MODIFY | REMOVE)

Upvotes: 22

Related Questions