0

I have the following json that I get when I invoke an AWS Lambda.

{
'$metadata': {
    httpStatusCode: 200,
    requestId: '1245',
    extendedRequestId: undefined,
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  ExecutedVersion: '$LATEST',
  Payload: Uint8Array(4) [ 110, 119, 106, 108 ],
  StatusCode: 200
}

This doesn't seem to be a valid JSON because of thePayload. How can I read the value inside the payload here? Appreciate any advice.

I tried the below way, but getting "undefined" when I print backendResponse.

const res = await client.invoke(command).then((data: InvokeCommandOutput) => {
            if (data?.FunctionError || data === undefined) {
                console.error('Error calling the backend lambda:', data);
            }
            else {
                try {
                    console.log("data", data);
                    const backendResponse = JSON.parse(Buffer.from(data.Payload!).toString('utf-8'))
                    console.log("Response from lambda", backendResponse);
                } catch (err) {
                    console.error('Error parsing backend lambda response', err);
                }
            }
        });
2
  • Check this answer to a similar question, that should help. There's also more information at the github issue mentioned in the question. Commented Jan 18, 2023 at 0:11
  • I tried the solution there, but still getting NULL :( Commented Jan 20, 2023 at 23:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.