Search code examples
database-designamazon-dynamodbaws-lambdaamazon-dynamodb-streams

DynamoDB Streams to Update Likes and Comments


I'm using DynamoDB for my backend, i need to maintain the Likes and Comments in Separate tables as in SQL and another table to maintain comments and likes counts per post

Total 3 tables

TableName - HashKey, RangeKey, Attributes

Likes - PostId, UserName, -

Comments - PostId, UserName, {text: "Jo jo"}

Counts - PostId, -, {Comments: 15, Likes: 15}

I need to update the Likes count in Counts table after inserting the Row in likes table/ comments table

Now i'm doing this in my app code (Java AWS SDK)

I heard about Streams and Triggers (Lambda Functions) - How can i update the counts table using the Streams

I read the several articles regarding the Streams, As per my understanding these are useful when we are using the Environment where we cannot able to do that action

Can anybody please clarify this?

Thanks in advance...


Solution

  • In Amazon Web Services, most of the actions have triggers as Lambda functions, when an action is executed, it will trigger the configured Lambda functions.

    I Created a stream for my tables and I configured a Lambda function for each table so that when a record is inserted the Lambda Function would be triggered and updates the aggregate count with my code.