Kemal Ahmed
Kemal Ahmed

Reputation: 703

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

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?

Upvotes: 12

Views: 4277

Answers (1)

Michael Willingham
Michael Willingham

Reputation: 912

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.

Upvotes: 14

Related Questions