The following code connected to Redshift database but returning an empty response even the response will be displayed in the console.log, why?
index.js
const config = {
user: 'user',
database: 'database',
password: 'password',
port: port,
host: 'hostname',
};
var response = [];
console.log('Before Connection');
exports.handler = function index(event, context, callback) {
var redshiftClient = new Redshift(config, {rawConnection:true});
redshiftClient.connect(function(err){
console.log('After Connection');
if(err) throw err;
else{
redshiftClient.query('SELECT * FROM customer', {raw: true}, function(err, data){
if(err) throw err;
else{
response = data;
console.log(data);
redshiftClient.close();
return response;
}
});
}
});
return response;
};