简体   繁体   中英

How to get notified when a AWS Dynamo DB entry are updated?

I would like to be notified when a DynamoDB table changes, the same way as Google Firebase Realtime Database.

I consuming this service in a frontend javascript application.

DynamoDB and Firebase/Firestore are really different.

Firebase/Firestore is a realtime database where you scan subscribe to changes on the client. DynamoDB is a NoSQL Database to Store Key/Value Pairs.

More suitable for a similar use case is "AWS AppSync" which provides live updates like Firebase/Firestore does.

If you want to use DynamoDB nonetheless have a look at DynamoDB Streams to trigger an event on update of the table.

The questions is then how do you get the update to the client.

You could send a message to an SNS Topic, sending Push Notifications to the client if necessary.

But in the end you will build with DynamoDB Streams and SNS and maybe Lambda what Firebase/Firestore or "AWS AppSync" provides out of the box.

DynamoDB doesn't have realtime notification/trigger for update on table.

But in this case you can try to use DynamoDB Streams for Capturing Table Activity.

Here are some example use cases:

An application in one AWS region modifies the data in a DynamoDB table. A second application in another AWS region reads these data modifications and writes the data to another table, creating a replica that stays in sync with the original table.

A popular mobile app modifies data in a DynamoDB table, at the rate of thousands of updates per second. Another application captures and stores data about these updates, providing near real time usage metrics for the mobile app.

A global multi-player game has a multi-master topology, storing data in multiple AWS regions. Each master stays in sync by consuming and replaying the changes that occur in the remote regions.

An application automatically sends notifications to the mobile devices of all friends in a group as soon as one friend uploads a new picture.

A new customer adds data to a DynamoDB table. This event invokes another application that sends a welcome email to the new customer.

more details in this DynamoDB Streams document.

And here is how to you can integrate DynamoDB Streams with AWS Javascript SDK :

var dynamodbstreams = new AWS.DynamoDBStreams();
dynamodbstreams.describeStream(params, function (err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

We have some Event supported by DynamoDB Streams

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.

By the way, if you want to notify to your client via another way instead of DynamoDB Streams you can try to using Lambda Function follow this article .

Hope this can help you solving your issue.

I normally see the DynamoDB -> SNS topic pattern -> (With custom lambda).

If your application is for mobile have you taken a look at AWS SNS Mobile Push and seen if it would not be a better fit for your architecture.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM