I am new to AWS S3 and I am trying to read a csv from an S3 folder. For which I have the below logic.
var prefixList = [];
async function readConfig() {
const AWS = require("aws-sdk");
const s3 = new AWS.S3();
const csv = require("csv-parser");
const bucket = "my-bucket";
const objectkey = "/my/folder/path/filename.csv";
const params = { Bucket: bucket, Key: objectkey };
const configFile = s3.getObject(params).createReadStream();
configFile.pipe(csv()).on("data", (data) => {
prefixList.push(data["PREFIX"]);
});
logger.info("PrefixList: " + prefixList);
}
I am trying to print the list and it prints an empty list. The list is not getting appended by the elements from the csv file.
I have confirmed that the file is there in the bucket/folder path I have mentioned. And also, the header PREFIX is present in the csv file. But still something is preventing the push to the list.
Am I missing something here? Please help
EDIT:
Contents in the S3 file:
--------
PREFIX
--------
MR
MRS
MISS
MS
DR
REV
PROF
SIR
--------