I'm trying to read in a CSV from an s3 bucket using the csvtojson library in AWS Lambda, but it's not working properly. Locally, my code works. But when I upload it to Lambda, it doesn't return anything. There are no errors in the Lambda console, so I'm having a hard time debugging. My code is below.
const AWS = require('aws-sdk');
const csvtojson = require('csvtojson');
const s3 = new AWS.S3();
const params = {
Bucket: bucketName,
Key: pathToFile
};
const stream = s3.getObject(params).createReadStream();
csvtojson()
.fromStream(stream)
.then((json) => {
console.log('Locally, this returns the CSV as JSON. On Lambda, it does not.');
});
Does csvtojson not work on Lambda for some reason? Should I be using a different method to parse the CSV? Thanks!