Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'?

like image 455
C.Lee Avatar asked Dec 13 '16 01:12

C.Lee


People also ask

Can DynamoDB stream trigger Lambda?

With DynamoDB Streams, you can trigger a Lambda function to perform additional work each time a DynamoDB table is updated. Lambda reads records from the stream and invokes your function synchronously with an event that contains stream records.

Does DynamoDB have triggers?

Amazon DynamoDB is integrated with AWS Lambda so that you can create triggers—pieces of code that automatically respond to events in DynamoDB Streams. With triggers, you can build applications that react to data modifications in DynamoDB tables.


2 Answers

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)

like image 188
Peter Fennema Avatar answered Oct 05 '22 13:10

Peter Fennema


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
like image 22
Pirate Avatar answered Oct 05 '22 14:10

Pirate