React aws-sdk invokeWithResponseStream

0

Hello, I'm trying to invoke a lambda with ResponseStream using this code, but I get the error following the code:

runStreamLambda(param) {
        try {
            const lambda = new AWS.Lambda();
            const params = {
                Payload: JSON.stringify({ param }),
                FunctionName: 'streamResponse'
            };
            return lambda.invokeWithResponseStream(params).promise();
        } catch (error) {
            throw error;
        }
    }

ERROR
Can't find variable: payload

The interesting part is that if I do this, I get the response just fine:

runStreamLambda(param) {
        try {
            const lambda = new AWS.Lambda();
            const params = {
                Payload: JSON.stringify({ param }),
                FunctionName: 'streamAnswerQuery'
            };
            return lambda.invoke(params).promise(); // invoke instead of invokeWithResponseStream
        } catch (error) {
            throw error;
        }
    }

And if I call the streaming lambda in other ways, it works fine as well (for example calling the Lambda Function URL directly.

Carlo
質問済み 1年前402ビュー
1回答
1
承認された回答

This is a difference between API URI requests and language-specific AWS SDKs

you are using AWS SDK for Javascript but the invokeWithResponseStreammethod is for WS API URi request.

https://docs.aws.amazon.com/lambda/latest/dg/API_InvokeWithResponseStream.html

profile picture
エキスパート
回答済み 1年前

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

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

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

関連するコンテンツ