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 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南