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);
}
}
});