I'm a beginner with AWS, JavaScript and I'm trying to get data from an oracle database using the following code in a AWS Lambda function.
let conn = await this.getConnection(userName, password, connectString);
let results = await conn.execute(query, {}, {});
let data = results.rows.map(el => `${el}`);
console.log(data);
which gives me the following output on the console
[ "TEST_SESSION_0,121,High,Warning,7",
"TEST_SESSION_2,122,High,Error,11",
"TEST_SESSION_3,123,Low,Error,431,
"TEST_SESSION_4, ASMT_,103,Low,Fatal,10" ]
Now, my goal is to convert this output into CSV data stream and then upload into S3 bucket object output.csv for further processing. i tried below to convert into CSV but having issue to connect it back to S3 using AWS SDK and required NPM modules, when i test the below code i dont get any error but at the same time dont see data getting uploaded to S3. not sure where i'm doing wrong, appreciate any help..
stringify(results.rows, function(err, output){
if(err){
console.log('some error occured '+ err);
} else {
console.log(output); //gives me below output
//TEST_SESSION_0,121,High,Warning,7
//TEST_SESSION_2,122,High,Error,11
//TEST_SESSION_3,123,Low,Error,431
//TEST_SESSION_4, ASMT_,103,Low,Fatal,10
below code is to take CSV output to upload to S3 object
var param = {
Bucket: 'Test-Bucket',
Key: 'output.csv',
Body: new Buffer(fs.createWriteStream(output)) //can i pass the csv data that i captured above in "output"?
};
s3bucket.putObject(param, function(err, output){
if(err) console.log(err);
else console.log(output);
});
}
})