Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sent data triggered lambda function?

I want to send changed data triggered lambda function from DynamoDb. Then ı want to save this changed data different DynamoDb tables.

Programming Language: NodeJs

DynomaDb
Stream enabled: Yes
View type: New and old images

Lambda Function

'use strict';

console.log('Loading function');

exports.handler = (event, context, callback) => {
    //console.log('Received event:', JSON.stringify(event, null, 2));
    event.Records.forEach((record) => {
        console.log(record.eventID);
        console.log(record.eventName);
        console.log('DynamoDB Record: %j', record.dynamodb);
    });
    callback(null, `Successfully processed ${event.Records.length} records.`);
};

it is not working.

like image 939
Burhan Yılmaz Avatar asked Jun 05 '26 16:06

Burhan Yılmaz


1 Answers

DynamoDB streams and Lambda can be used for the above use case.

1) Enable the DynamoDB streams on Dynamodb table to stream the data

2) Create a Lambda function to consume the stream and write to another DynamoDB table. The Lambda function can be created in many programming languages (API). You can use AWS SDK to create the lambda function.

Refer the below links for more details.

Full documentation

Enable Streams and Lambda - Cross region replication use case

Stream View Type:-

StreamViewType—specifies the information that will be written to the stream whenever data in the table is modified:

KEYS_ONLY—only the key attributes of the modified item.

NEW_IMAGE—the entire item, as it appears after it was modified.

OLD_IMAGE—the entire item, as it appeared before it was modified.

NEW_AND_OLD_IMAGES—both the new and the old images of the item.

Event Name:-

record.eventName should have MODIFY when the data is updated in the DynamoDB table.

record.dynamodb should have the values based on the Stream view type. If you have selected NEW_AND_OLD_IMAGES, then it should have both old and new values.

eventName — (String) The type of data modification that was performed on the DynamoDB table:

INSERT - a new item was added to the table.

MODIFY - one or more of an existing item's attributes were modified.

REMOVE - the item was deleted from the table

like image 61
notionquest Avatar answered Jun 07 '26 13:06

notionquest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!