aws / aws-appsync-community

The AWS AppSync community
https://aws.amazon.com/appsync
Apache License 2.0
506 stars 32 forks source link

Appsync should have a built in way to produce side effects in a pipeline function #356

Open jay-herrera opened 5 months ago

jay-herrera commented 5 months ago

When writing a pipeline function, there should be a way to return data to the endpoint and still run some Appsync resolver function in the background. This could be very useful for things like analytics or push notifications, times when you want a user to send a request to an Appsync endpoint and get back data as soon as possible while also triggering some other mutation behind the scenes. Currently, the best way to do this would be to listen for an event on the data source that you're mutating and run a Lambda function, but that quickly becomes a mess of managing which events need to be tied to which data sources, filtering, and managing dedicated Lambda functions for small tasks. Also, it does not allow you to run side effects on Queries. I am sure there are workarounds, but first-class support would make Appsync much more enjoyable to use.

jay-herrera commented 5 months ago

One solution to this could be to allow asynchronous invocation of a Lambda function, so that you can invoke the function without waiting for a response. You would still have the small lambdas, but at least you wouldn't have to worry about managing events or SNS queues

onlybakam commented 2 months ago

Hey @jay-herrera we just released support for async invocation of Lambda functions. Give it a try.

export function request(ctx) {
  return {
    operation: 'Invoke',
    invocationType: 'Event',
    payload: { field: 'getPost', arguments: ctx.args },
  };
}

https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-lambda-js.html