I am new in node.js.
I made a function that returns an array of objects.
When I try to display it in the console, it shows the message Undefined.
Here is the function:
async function allBucketKeys(s3, bucket) {
const params = {
Bucket: bucket,
};
var keys = [];
for (;;) {
var data = await s3.listObjects(params).promise();
data.Contents.forEach((elem) => {
keys = keys.concat(elem.Key);
});
if (!data.IsTruncated) {
break;
}
params.Marker = data.NextMarker;
}
console.log(keys);
return keys;
}
var s3 = new AWS.S3()
array = allBucketKeys(s3, "mymplifyroject-20190123180140-deployment").keys;
console.log(array);