Description
Describe the bug
When using the new AWS Client Lambda NPM Module, and when invoking a lambda, data from Payload
is returned in a Uint8Array
. I can't find a way to resolve/get the data in the original JSON format that it should be?
Your environment
SDK version number
"@aws-sdk/client-lambda": "^3.12.0",
Is the issue in the browser/Node.js/ReactNative?
NodeJS
Details of the browser/Node.js/ReactNative version
Node 14.6.1
Steps to reproduce
Lambda A tried to invoke Lambda GITHUB_TOKEN_FUNCTION
const { LambdaClient, InvokeCommand } = require('@aws-sdk/client-lambda');
module.exports = {
getGitHubToken: async () => {
const client = new LambdaClient({ region: process.env.REGION });
const params = {
FunctionName: process.env.GITHUB_TOKEN_FUNCTION,
LogType: 'Tail',
Payload: '',
};
const command = new InvokeCommand(params);
try {
const { Payload } = await client.send(command);
console.log(Payload)
return str;
} catch (error) {
console.log(error.message);
throw error;
}
},
};
GITHUB_TOKEN_FUNCTION should return this:
const res = {
statusCode: 200,
body: JSON.stringify({
token,
}),
However, when I console.log(Payload)
I get this:
In the old module (v2) I never got this, I just got the data back as returned from the GITHUB_TOKEN_FUNCTION
. Which should be:
const res = {
statusCode: 200,
body: JSON.stringify({
token,
}),
I have checked the CloudWatch logs for GITHUB_TOKEN_FUNCTION
and it is successfully sending that object. Lambda A just receives it in a different format that I can't seem to get into the expected one.
Observed behavior
I get some sort of Unit8Array
back that I can't find out how to turn into the data I expect.
Expected behavior
Payload
===
const res = {
statusCode: 200,
body: JSON.stringify({
token,
}),
My Question:
How do I resolve data from Unit8Array
to the data I was expecting from the Lambda response? Which is a JSON Object?