I am using AWS Lambda
with NodeJS runtime and I recently received a notification from AWS
telling that they will stop maintaining lambdas
running on node.js 6.10
runtime.
Basically, I am trying to get objects from S3
and create a stream from these objects in order to extract the data from a xlsx
file.
This is the code I am trying to execute inside my lambda. This chunk of code worked on the node.js 6.10
runtime but does not work on the node.js 8.10
runtime.
function getWorkbookFromS3(s3Params): Promise<XLSX.WorkBook> {
return new Promise((resolve, _reject) => {
const buffers = [];
S3Service.getObject(s3Params).createReadStream()
.on('error', (error) => {
console.log(error);
}).on('data', (chunk) => {
buffers.push(chunk);
}).on('end', () => {
const buffer = Buffer.concat(buffers);
const workbook = XLSX.read(buffer, { type: 'buffer', cellDates: true });
resolve(workbook);
})
});
}
Any clue on how to solve this?
The issue is related to the use of this function inside a lambda
. I did not get any error, neither any result because once the lambda
stopped its execution, the code inside the function getWorkbookFromS3(s3Params)
could not get executed since it is a promise.
The way I called this function before was like this:
getWorkbookFromS3(s3Params).then((d) => {
// do someting
});
But it didn't work. As a result, I had to add an await
keyword in order to force the promise
to be executed and prevent the lambda
to stop its execution.
await getWorkbookFromS3(s3Params).then((d) => {
// do someting
});