如何直接订阅我的 AWS AppSync 数据源? [英] How do I subscribe directly to my AWS AppSync data source?

查看:17
本文介绍了如何直接订阅我的 AWS AppSync 数据源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到步骤函数的 DynamoDB,我正在构建一个 UI 来显示更改.我将数据库连接到 AppSync 实例,并尝试通过 AppSync 使用订阅,但他们似乎只观察到当前 AppSync 中的突变.

I have a DynamoDB connected to step functions and I am building a UI to display changes. I connected the DB to an AppSync instance and have tried using subscriptions through AppSync, but it seems they only observe mutations within the current AppSync.

如何直接订阅数据源更改?

How can I subscribe to the data source changes directly?

推荐答案

你说得对.目前,AppSync 订阅仅从 GraphQL 突变触发.如果从 AppSync 以外的来源对 DynamoDB 进行了更改,则不会触发订阅.

You are correct. Currently, AppSync Subscriptions are only triggered from GraphQL Mutations. If there are changes made to the DynamoDB from a source other than AppSync, subscriptions will not trigger.

如果您想跟踪对 DynamoDB 表所做的所有更改并使用 AppSync 发布它们,您可以执行以下操作:

If you want to track all changes being made to DynamoDB table and publish them using AppSync, you can do the following:

1) 设置 DynamoDB 流以捕获更改并将更改提供给 AWS Lambda

1) Setup a DynamoDB stream to capture changes and feed the changes to AWS Lambda

https://docs.aws.amazon.com/amazondynamodb/最新的/developerguide/Streams.htmlhttps://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.Lambda.html

2) 使用本地(无数据源)解析器设置 AppSync 突变.您可以使用它向订阅者发布消息,而无需写入数据源.

2) Setup an AppSync mutation with a Local (no datasource) resolver. You can use this to publish messages to subscribers without writing to a datasource.

https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-local-resolvers.html

3) 使 DynamoDB Stream Lambda 函数(在步骤 1 中设置)调用 AWS AppSync 突变(在步骤 2 中设置).

3) Make the DynamoDB Stream Lambda function (setup in step 1) call the AWS AppSync mutation (setup in step 2).

这将允许向 AppSync 订阅者发布对 DynamoDB 表所做的所有更改,无论更改来自何处.

This will enable publishing ALL changes made to a DynamoDB table to AppSync subscribers, regardless of where the change came from.

这篇关于如何直接订阅我的 AWS AppSync 数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆