0

I have a mobile application (Native iOS and Android) that I'd like to have receive realtime state information on whether or not to display certain things in the UI.

Our current backend runs Sails and has a MySQL Database. Sails is deployed over EC2 and the MySQL DB uses AWS RDS. I've been reading about AWS AppSync and believe it's a viable solution to pushing realtime state information from the MySQL DB up to the frontends.

My question is, is it possible to connect AppSync to subscribe to the RDS instance, and if so, does the solution require a Lambda function to run the actual querying against the DB? The entire concept is still new to me & today's the first time I've heard of GraphQL, so any and all information on how AppSync works and how this could be implemented would be great!

Currently I believe I'd create a GraphQL Schema that matches the state information I need, AppSync would expose an API for me to subscribe to with their mobile SDKs?, and I could use my Sails backend to send GraphQL mutations to AppSync which would then (somehow?) update the mySQL DB? Is this a proper flow and could somebody please fill in the gaps here :)

JamesRichardson
  • 131
  • 2
  • 13

1 Answers1

1

Are you trying to update the database directly/bypassing AppSync?

If yes, the lambda solution you mentioned maybe useful. If no, by setting up subscriptions and mutations to the database via AppSync is sufficient.

Sunny
  • 176
  • 4
  • If I were to bypass AppSync & update the database directly via my Sails backend, is there anyway for AppSync to still be able to subscribe & push that data up to my application? Or are Mutations via AppSync a required trigger to update my AppSync Subscriptions? – JamesRichardson Sep 09 '19 at 23:48
  • Also if yes, how could I setup my subscriptions & mutations to connect to a MySQL RDS? is that even possible? – JamesRichardson Sep 09 '19 at 23:54
  • It only works either through the DATA API for aurora serverless https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-rds-resolvers.html or through a lambda in VPC. – Sunny Sep 10 '19 at 00:32
  • 1
    There is a sample for setting it up through a lambda that runs in the same VPC as the RDS instance on github you can refer(if it is the same use case): https://github.com/aws-samples/aws-appsync-rds-aurora-sample – Sunny Sep 10 '19 at 00:33
  • Ah thank you so much for the references! So (please correct me if I’m wrong) but my understanding: I must use BOTH Mutations and Subscriptions (cannot use subscriptions if I use Sails backend to directly update database), and with Mutations & Subscriptions, I must make them to my MySQL DB via Lambda or Aurora. Is this right? Also, what are the benefits/downsides of Lambda vs Aurora? – JamesRichardson Sep 10 '19 at 00:35
  • Also, I see the github reference is using Aurora. That should be interchangeable with a RDS MySQL instance correct? – JamesRichardson Sep 10 '19 at 00:43
  • Mutations and Subscriptions is not a must. You can do whatever you want at your case. For the Data API it only works for certain versions of mysql, For lambda it has the cold start issue. You can do some research and see what is best for you. – Sunny Sep 10 '19 at 00:43
  • I'm a little confused, if I use a subscription which calls a lambda function to get my data value, how will that Subscription be triggered? Doesn't that same value need to be changed via a Mutation? – JamesRichardson Sep 10 '19 at 14:41