Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 518
Kemal Ahmed Avatar asked Aug 02 '18 17:08

Kemal Ahmed


People also ask

What are AppSync subscriptions?

AppSync subscriptions allow you to push events to clients in real-time when a change happened. This is great for applications that show data that can change without user interaction, which is the case for almost all applications.

What are available data source in AWS AppSync?

AWS AppSync has support for automatic provisioning and connections with certain data source types. AWS AppSync supports AWS Lambda, Amazon DynamoDB, relational databases (Amazon Aurora Serverless), Amazon OpenSearch Service, and HTTP endpoints as data sources.

Where are AppSync data stored?

Application data is stored at rest in your AWS account and not in the AWS AppSync service. You can protect access to this data from applications by using security controls with AWS AppSync including AWS Identity and Access Management (IAM), as well as Amazon Cognito User Pools.

What type of API is used for the AppSync service?

A single data API AWS AppSync securely connects your GraphQL API to data sources like AWS DynamoDB, RDS, OpenSearch, and Lambda. Adding caches to improve performance, authentication to secure your data, and client-side data stores that keep off-line clients in sync are just as easy.


1 Answers

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.

like image 105
Michael Willingham Avatar answered Nov 03 '22 07:11

Michael Willingham