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.
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ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ