7

As the title says I want to trigger a subscription event from my code.

Think about an use case, where a user wants to search the Internet for the cheapest flight. A Lambda function starts scraping popular flight tickets offering websites and with each find it sends a subscription event to an app. Is this case possible to be hosted with AppSync?

Konrad Kalemba
  • 1,209
  • 13
  • 21

1 Answers1

3

This should be possible with AWS AppSync. A design that comes to mind is:

  • App users authenticate with Cognito User Pools.
  • Define a mutation for sending events to subscribers. Attach a Local Resolver to this mutation since the only behavior you want is delivery of a notification. Something like notify(username: String!) should work.
  • When the Lambda is ready to notify, look up the username of the subscriber and then call notify thru that AppSync endpoint.

There are other designs that you can implement but this was the first reasonable one that came to mind for me.

Rohan Deshpande
  • 3,535
  • 1
  • 26
  • 31
  • 1
    Hi @Rohan, how does the lambda authenticate to AppSync in this scenario? – macbutch Jul 24 '18 at 01:21
  • @macbutch ICYMI, there is a good write up on how to use the credentials provided by the role granted to the lambda function to sign an HTTP request to the AppSync endpoint here: https://read.acloud.guru/backend-graphql-how-to-trigger-an-aws-appsync-mutation-from-aws-lambda-eda13ebc96c3 – Lance Harper Jan 09 '19 at 17:05
  • I found the part of your answer "When the Lambda is ready to notify..." a bit unclear. What I wanted to know was "How do I access appsync from within a lambda", which I found here: https://stackoverflow.com/questions/60293311/how-to-send-a-graphql-query-to-appsync-from-python . I hope this saves others some time. – tofarr Dec 30 '22 at 15:24