Search code examples
amazon-web-servicesamazon-dynamodbamazon-dynamodb-streams

Print DynamoDB Stream output


I have a DynamoDB with streams enabled. I used AWS console to create a lambda and gave all the permissions necessary. I just want to look at the output generated by the stream when I create a record. For this I am manually creating a record in my table. Now, how do I print this record? All the examples I see are using SNS and reading the data from the message. I don't want to use SNS. How can I just print the output? Thanks in advance.


Solution

  • Simple Node.js example to log DynamoDB streams records to CloudWatch Logs where you can read them:

    console.log('Loading function');
    
    exports.handler = function(event, context, callback) {
        console.log(JSON.stringify(event, null, 2));
        event.Records.forEach(function(record) {
            console.log(record.eventID);
            console.log(record.eventName);
            console.log('DynamoDB Record: %j', record.dynamodb);
        });
        callback(null, "message");
    };