Gene Ellis
Gene Ellis

Reputation: 273

DynamoDB Streams + Lambda + NodeJS

Pretty basic question. I have two DynamoDB tables. Table1 contains a list of values, and Table2 will contain an aggregate of values (average, etc).

I am using DynamoDB streams to trigger a lambda function to calculate aggregate values from the data in Table1, then update Table2 with those values. My question is, will the DynamoDB stream contain the ENTIRE table1 or just the new record?

I'm just tweaking the lambda functions to calculate the averages and store into Table2 and I'm just trying to plan the best way to do this. Everything seems to be working. Just stumbling on getting the data from table1. Any other tips regarding forEach for the records will be highly appreciated as well. Thank you!

Upvotes: 1

Views: 4068

Answers (1)

RoberMP
RoberMP

Reputation: 1356

Only the modified field, otherwise it would not make much sense to stream the entire database each time right?. from the docs: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.Lambda.Tutorial.html

You will receive a message like:

{
    "Records": [
        {
            "eventID": "7de3041dd709b024af6f29e4fa13d34c",
            "eventName": "INSERT",
            "eventVersion": "1.1",
            "eventSource": "aws:dynamodb",
            "awsRegion": "us-west-2",
            "dynamodb": {
                "ApproximateCreationDateTime": 1479499740,
                "Keys": {
                    "Timestamp": {
                        "S": "2016-11-18:12:09:36"
                    },
                    "Username": {
                        "S": "John Doe"
                    }
                },
                "NewImage": {
                    "Timestamp": {
                        "S": "2016-11-18:12:09:36"
                    },
                    "Message": {
                        "S": "This is a bark from the Woofer social network"
                    },
                    "Username": {
                        "S": "John Doe"
                    }
                },
                "SequenceNumber": "13021600000000001596893679",
                "SizeBytes": 112,
                "StreamViewType": "NEW_IMAGE"
            },
            "eventSourceARN": "arn:aws:dynamodb:us-east-1:123456789012:table/BarkTable/stream/2016-11-16T20:42:48.104"
        }
    ]
}

Don't know what kind of aggregates you need nor your use case so I can't help with that.

Upvotes: 1

Related Questions