Search code examples
amazon-cognitoaws-appsync

Notify Appsync User on Friend Request


Im using Appsync and Cognito for a browser based Vue application. I have a model with 2 DynamoDB tables one to keep track of Users and another for Follows. I want to be able to notify users when another user follows them by email. How can I leverage Cognito, AppSync or SES to do this

Here is my model:

type User {
    username: String!
    following: [Follow]
}

type Follow {
    username: String!
    following: String!
}

How can I notify users via e-mail on a new follow?


Solution

  • That should be totally possible, I can think of a few ways to do this:

    1) Set up DynamoDB streams on your follows table, then hook up a Lambda to that stream by using the stream as an event source, meaning the Lambda would poll the stream on it's own so you don't have to worry about getting the event. In that Lambda, parse out the follower and followee, and send an email to SES with the appropriate context.

    2) Instead of a direct DynamoDB data source, use a Lambda data source. In this Lambda data source, first communicate with Dynamo as you would normally, then directly call SES right there.

    3) Set up pipeline resolvers on a new follow mutation. The first stage would be a pure Dynamo data source, then the following one would be tasked with sending the email. This is effectively the same as 2, just with cleaner separation of logic.

    I would personally say 1 or 3 are great options, but it's a bit up to your application needs/personal preferences.