appsync lambda mutate and publish

0

I've seen how to create a lambda to perform an appsync mutation, invoking back ends such as dynamo. I've also seen examples of lambdas, which are appsync clients, which can publish events that clients subscribe to.

I've seen another example of this essentially working using a websocket AWS API endpoint with

conn = boto3.client("apigatewaymanagementapi"...
for chunk in s:
    conn.post_to_connection(**params)

I was hoping that the lambda would somehow have access to the appsync instance to receive a mutation request and then publish a result in a stream of messages to the client. Is this feasible, or do I just need to set up the lambda to send mutation events using its own separate connection to appsync using boto3? Instead of just returning a result, I want to start that stream of events going.

This is for a streaming AI use case with a python lambda:

  • Client - sends mutation request to create a question with the same ID and subscribes to answerChunks coming back with that ID
  • Lambda - receives the request, does "AI magic," - and then streams the response back in multiple "answerChunk" published events until the answer is finished.
  • Client - aggregates the chunks into the output response display.
已提问 6 个月前263 查看次数
1 回答
1
已接受的回答

Hello,

I understand that you wish to call an App sync from a Lambda function. Please follow the steps in documentation at link [1] , this will help you to perform both a query as well as a mutation from a Lambda function using Node.js (If you wish to make use of amplify).

You can use the pagination to stream the response back in multiple answerChunk. The documentation at link[2] will help you to implement pagination in app sync.

Here, for streaming we need to ensure that the Lambda function does not timeout, Kindly note that Lambda is configured with the timeout of 15 minutes [3]. The best approach here is to use the Lambda function for the mutation and for streaming the response back in answerChunks you can use app sync pagination.

Further if you have any queries please reach out to AWS Premium Support.

Thank you.


REFERENCES

[1] https://docs.amplify.aws/guides/functions/graphql-from-lambda/q/platform/ios/

[2] https://docs.amplify.aws/guides/api-graphql/graphql-pagination/q/platform/js/

[3] https://aws.amazon.com/about-aws/whats-new/2018/10/aws-lambda-supports-functions-that-can-run-up-to-15-minutes/

AWS
已回答 6 个月前
profile picture
专家
已审核 1 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则