How do I subscribe directly to my AWS AppSync data source?

拟墨画扇 提交于 2019-12-04 09:36:11

问题


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?


回答1:


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.

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

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

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.html https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.Lambda.html

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) Make the DynamoDB Stream Lambda function (setup in step 1) call the AWS AppSync mutation (setup in step 2).

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



来源:https://stackoverflow.com/questions/51659099/how-do-i-subscribe-directly-to-my-aws-appsync-data-source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!