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