简体   繁体   English

如何更新AWS Dynamo数据库条目时得到通知?

[英]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. 我想在DynamoDB表更改时收到通知,方法与Google Firebase实时数据库相同。

I consuming this service in a frontend javascript application. 我在前端javascript应用程序中使用了此服务。

DynamoDB and Firebase/Firestore are really different. DynamoDB和Firebase / Firestore确实不同。

Firebase/Firestore is a realtime database where you scan subscribe to changes on the client. Firebase / Firestore是一个实时数据库,您可以在其中扫描订阅客户端上的更改。 DynamoDB is a NoSQL Database to Store Key/Value Pairs. DynamoDB是用于存储键/值对的NoSQL数据库。

More suitable for a similar use case is "AWS AppSync" which provides live updates like Firebase/Firestore does. 更适合类似用例的是“ AWS AppSync”,它提供实时更新,如Firebase / Firestore一样。

If you want to use DynamoDB nonetheless have a look at DynamoDB Streams to trigger an event on update of the table. 但是,如果您想使用DynamoDB,请查看DynamoDB流以在表更新时触发事件。

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. 您可以向SNS主题发送消息,并在必要时向客户端发送推送通知。

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 Streams和SNS以及Lambda构建Firebase / Firestore或“ AWS AppSync”提供的即用型功能。

DynamoDB doesn't have realtime notification/trigger for update on table. DynamoDB没有实时通知/触发器来更新表。

But in this case you can try to use DynamoDB Streams for Capturing Table Activity. 但是在这种情况下,您可以尝试使用DynamoDB流来捕获表活动。

Here are some example use cases: 以下是一些示例用例:

An application in one AWS region modifies the data in a DynamoDB table. 一个AWS区域中的应用程序会修改DynamoDB表中的数据。 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. 另一个AWS区域中的第二个应用程序读取这些数据修改并将数据写入另一个表,从而创建一个与原始表保持同步的副本。

A popular mobile app modifies data in a DynamoDB table, at the rate of thousands of updates per second. 流行的移动应用程序以每秒数千次更新的速度修改DynamoDB表中的数据。 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. 全球多人游戏具有多主机拓扑,可将数据存储在多个AWS区域中。 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. 新客户将数据添加到DynamoDB表。 This event invokes another application that sends a welcome email to the new customer. 此事件将调用另一个向新客户发送欢迎电子邮件的应用程序。

more details in this DynamoDB Streams document. DynamoDB Streams文档中的更多详细信息。

And here is how to you can integrate DynamoDB Streams with AWS Javascript SDK : 这是将DynamoDB流与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 DynamoDB流支持一些事件

eventName — (String) The type of data modification that was performed on the DynamoDB table: eventName —(字符串)在DynamoDB表上执行的数据修改的类型:

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 . 顺便说一句,如果您想通过其他方式而不是DynamoDB Streams通知客户端,则可以尝试使用Lambda函数,请遵循本文

Hope this can help you solving your issue. 希望这可以帮助您解决问题。

I normally see the DynamoDB -> SNS topic pattern -> (With custom lambda). 我通常会看到DynamoDB-> SNS主题模式->(带有自定义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. 如果您的应用程序是用于移动设备的,请看一下AWS SNS Mobile Push ,看看它是否更适合您的架构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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