I am trying to transform a CSV file using Fastcsv nodejs package. Interestingly, the code snippet works locally on my system well. However, if I try to integrate it with AWS lambda program it gives write after end error.
var stream = fs.createReadStream(s3EventInfo.inputDownloadLoc)
.pipe(csv.parse({headers: true}))
//pipe the parsed input into a csv formatter
.pipe(csv.format({headers: true}))
//Using the transfrom function from the formatting stream
.transform(function(row, next){
transformLine(row, next);
})
.pipe(fs.createWriteStream(s3EventInfo.outputFileLoc))
.on("end", function(){
callback();
});
Here is the error in aws logs..
Error: write after end
at writeAfterEnd (_stream_writable.js:133:12)
at PassThrough.Writable.write (_stream_writable.js:181:5)
at write (_stream_readable.js:602:24)
at flow (_stream_readable.js:611:7)
at _stream_readable.js:579:7
at process._tickDomainCallback (node.js:486:13)
Please help in understanding and resolving the issue.