0

When I try this code in local its works fine but not in an AWS Lambda function.

var Redshift = require('node-redshift');
   
var client = {
  user: 'root',
  database: 'yourdatabasename',
  password: 'yourpassword',
  port: 5439,
  host: 'localhost',
};

var redshiftClient = new Redshift(client, {rawConnection:true});

exports.handler = async (event) => {
    let response = [];
    redshiftClient.connect(function(err){
    console.log('After Connection');
    if(err) throw err;
    else{
      redshiftClient.query('SELECT * FROM world.country', {raw: true}, function(err, data){
        if(err) throw err;
        else{
            response = data;
          console.log(data);
          redshiftClient.close();
        }
      });
    }
  });
  
    return response;
}; 

Could anyone tell me what's the matter with my coding?

Thank you very much!

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • Does this answer your question? [How to return value from an asynchronous callback function?](https://stackoverflow.com/questions/6847697/how-to-return-value-from-an-asynchronous-callback-function) – luk2302 Jun 18 '21 at 11:20
  • This code works fine in my local machine but not in aws lambda function it returns null – krishnakumar Balasubramaniam Jun 18 '21 at 11:26
  • 1
    No, it does not work fine on any machine unless you have the wrong understanding of "works fine". Where you `return response` `response` is always `[]` no matter the machine you run this on. – luk2302 Jun 18 '21 at 11:28

0 Answers0