2

I was trying to implement a Lambda function based on as a trigger to a MODIFY event on a DynamoDB table. This trigger was to be used to further modify the table based on calculations performed on the new entries. But since this would also be a 'MODIFY' event it would trigger the lambda again, which might start of infinite triggers of lambda functions.

How do stop the lambda from getting triggered infinitely?

var AWS = require('aws-sdk');
// extra
const docClient = new AWS.DynamoDB.DocumentClient();

exports.handler = async (event , context , callback) => {
    // TODO implement
    
    event.Records.forEach((record) => {
        console.log('Stream record: ', JSON.stringify(record, null, 2));
        // logic to find insert type / modify type 
        if(record.eventName == 'MODIFY'){
             // extract student id, and marks from event itself (save I/O)
            console.log("Printing new image values",JSON.stringify(record.dynamodb.NewImage,null,2));
             // modify the same record once new value is calculated
             
             //############# method to modify /update dynamo db  #################
             
             //############# end code ###############
        }
        
    });
    
    console.log(event);
    const response = {
        statusCode: 200,
        body: JSON.stringify(event),
    };
    
    
    
    return response;
};

Here the code i am using in lambda which is triggered by a dynamodb event

1 Answer 1

1

A simple solution is to signify Lambda when not to alter the record anymore

This solution is dependent on your actual use case and if you can save a certain condition that the current record should not be processed anymore

Sometimes it can be a simple property such as

  • Processed = true
  • LastProcessTime = 1602232746

saved directly into the record

Checkout other discussions around this also

https://www.reddit.com/r/aws/comments/7cvqsy/is_it_an_antipattern_to_write_to_dynamodb_from_a/

DynamoDB streams - write data back into table

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.