Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I trigger a Lambda function or SNS event in response to an AppSync GraphQL Mutation? #3565

Closed
scherroman opened this issue Jul 1, 2019 · 2 comments

Comments

@scherroman
Copy link

scherroman commented Jul 1, 2019

Which Category is your question related to?

Usage Question

What AWS Services are you utilizing?

Amplify, AppSync, Lambda, SNS, DynamoDB

Provide additional details e.g. code snippets

AWS AppSync/GraphQL subscriptions coupled with AWS Amplify sound amazing, since out of the box you can subscribe all your clients to high-level domain events specified in your schema.

Though it seems like a natural extension that there should be a way to broadcast all those events to a service like lambda or SNS to react internally to those events. Maybe you want to log the events, re-index or aggregate updated data, or send an email or push notification to a user. Just like DynamoDB Streams allows you to trigger a lambda upon to updates on a table. Is anyone aware of a good way to achieve this?

There appears to be no AppSync trigger source for lambda, but it seems like there might be a couple of ways to do this otherwise:

  1. Create a long-running process/service on ECS/Fargate that subscribes to every mutation it wants to broadcast to SNS/Lambda. Though you would have to manage and scale that process yourself 😬

  2. Use DynamoDB Streams as a lambda trigger. However, a DynamoDB table change event is lower-level than a GraphQL mutation event, and this assumes your only data source is DynamoDB, whereas AppSync/GraphQL can plug into many other data sources.

  3. Create lambda resolvers for every mutation that also broadcast the event to SNS/Lambda. For simply broadcasting SNS events, perhaps theres a clever way to use pipeline resolvers to attach a reusable resolver to every mutation...

I'm not sure how the Amplify framework powers their @searchable transformer, whether its the 2nd or 3rd method, or something else altogether, but it seems like that's in the same ballpark (re-indexing the data in Elasticsearch in response to an update). I do remember hearing you can write your own transformers ... perhaps one could write their own transformer @broadcasted that also broadcasts all mutation events to SNS 🤔

I'm surprised I haven't seen much if any discussion surrounding this topic. If anyone has some ideas or if I'm thinking about this the wrong way let me know!

@scherroman
Copy link
Author

scherroman commented Jul 1, 2019

Closing as I think is more appropriate to ask on the amplify-cli project where the GraphQL Transformer exists today.

Opened a question issue here

@scherroman scherroman changed the title How can I trigger a Lambda function or SNS event in response to an AppSync GraphQL Mutation? Can I trigger a Lambda function or SNS event in response to an AppSync GraphQL Mutation? Jul 1, 2019
@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant