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 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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With