簡體   English   中英

無法從 AWS lambda 連接 AWS redshift

[英]Unable to connect AWS redshift from AWS lambda

我正在嘗試從我的 AWS Lambda function 連接到 AWS Redshift:

var Redshift = require('node-redshift');
const getLOOKUP_LOV_JSON= async ()=>{
 try{

   
        
    var client = {
        
  host: "redshift-host",
  user: 'admin',
  database: 'dev',
  password: 'password',
  port: "5439"
  
};
  return new Promise(function (resolve, reject) {
      
      
var redshiftClient = new Redshift(client, {rawConnection: true});
     
      
           console.log("before Connect");
 redshiftClient.connect(function(err){
       console.log("after connect");
    if(err){
      console.log(err);
      throw err;
    }
    else{ 
      
      redshiftClient.query('SELECT * FROM "Persons"', {raw: true}, function(err, data){
        if(err){
          
          console.log(err);
          throw err;
        }
        else{
          console.log(data);
         redshiftClient.close();
        }
      });
    }
  });

我的代碼執行到連接方法之前,我的記錄器中沒有任何問題,它只打印“連接之前”。

AWS Lambda function 需要配置為連接到與 Amazon Redshift 集群相同的 VPC 中的私有子網。

你會遇到超時問題。 to fix this you need to put your lambda function in VPC you can do that following the tutorial https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html

Then add inbound rule in security group of Redshift for lambda function security group on port 5439 https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-security-groups.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM