2
votes

I am using AppSync with Aurora/RDS. I would like that in some cases, when a query/mutation is sent to the db, then, after that, I want to send an email and push notification, but this should be detached from the query/mutation, that is, it does not matter if it fails or works. At the moment I see all these options: Can you tell me which one I should use?

  1. Create a query that calls a lambda function that sends the push/email and call it from the client once the actual query/mutation is done. I don't like this because the logic is in the client rather than the server. Seems easy to implement, and I guess it is easy to ignore the result of the second operation from a client point of view.

  2. A variation of the previous one. Pack both operations in a single network request. With GraphQL, that is easy, but I don't want the client waits for the second operation. (Is it possible to create lambda functions that return immediately, like a trigger of other functions?)

  3. Attach my queries/mutations to lambda functions instead of RDS directly. Then, those lambda functions call other lambda functions for notifications. Seems more difficult to program, but more micro-services architecture friendly. Probably this is the best one, not sure.

  4. Use SQL triggers and call lambda functions from those triggers. I don't know if this is even possible. Researching...

  5. Use pipelines resolvers. The first one is the query/mutation, the second one is the lambda function that sends the push/email. I would say this is a bad option because I don't want the client to wait for the second operation or manage the logic when the second resolver fails.

  6. Amazon RDS Events: It appears it is possible to attach lambda functions to specific AWS RDS events. https://docs.aws.amazon.com/lambda/latest/dg/services-rds.html It seems it is about creating DBs, restoring... and that kind of things. I don't see anything like creating a row, updating a row... So, I discard this unless I am wrong.

  7. Invoking a Lambda Function with an Aurora MySQL Stored Procedure CALL mysql.lambda_async ( lambda_function_ARN,lambda_function_input ) https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Integrating.Lambda.html "For example, you might want to send a notification using Amazon Simple Notification Service (Amazon SNS) whenever a row is inserted into a specific table in your database." That is exactly what I am looking for. I like this idea, but I don't know if that is possible with Aurora Serverless. Researching... It seems it is not possible when using server-less: https://www.reddit.com/r/aws/comments/a9szid/aurora_serverless_call_lambda/

  8. Use step functions: No idea about how to use it.

  9. Somehow, attach this lambda notification function to GraphQL/AppSync instead of the database, but I guess it is not a good idea because I need to read the database to the push notification token and the email of the use who is going to receive the notifications.

Which method do you recommend me? I am using amplify cli. Thanks a lot.

1
Thanks but when using AppSync, you have to use Aurora Serverless, and your link is only about Aurora, it does not work with serverless :( - Ricardo
I face the same problem, I give up, it seems the best option is to use lambda function but I was looking for a way to do it "decoupled" from the main code. like a trigger. But it seems is not possible to create triggers directly from the resolvers - eli.rodriguez
@eli.rodriguez Using microservices is the correct approach, but too complex, I will use use a specific query to send push and emails, and pipelines to get info from the database and pass that to the lambda function, because accesing the database from the lambda is also a pain in the ass. Check pipilenes here: github.com/aws-amplify/amplify-cli/issues/3321 - Ricardo

1 Answers

1
votes

Currently AWS AppSync can only send notifications when the app is active. We are looking into implementation of the non active case.

If you want to send notifications when the app is not active, you can use the push notifications on iOS: silent push/interactive push or push notifications on Android.

If you want to send emails, voice/text message or notifications on phone when the app is not active, you can integrate with Amazon Pinpiont.