尝试通过AWS Lambda连接到Redshift [英] Trying to Connect to Redshift Over AWS Lambda

查看:406
本文介绍了尝试通过AWS Lambda连接到Redshift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的AWS Redshift数据库中使用 node-postgres 客户端.

I'm using the node-postgres client to my AWS Redshift database.

在本地,我可以在node中运行以下代码,获取">>连接"和">>>成功查询的打印语句.jsonResult:".

Locally, I'm able to run the following code in node, getting print statements for ">> connected" and ">>> successful query. jsonResult: ".

但是,当我在Amazon Lambda中运行此代码时,除了尝试连接..."之外,我看不到任何日志语句.

However, when I run this code in Amazon Lambda, I don't see any log statements besides "trying to connect...".

console.log("trying to connect...");
var r = pg.connect(conString, function(err, client) { 
  if(err) {
    return console.log('>> could not connect to redshift', err);
  }
  console.log(">> connected");
  client.query('SELECT * FROM my_table', function(err, result) {
    if(err) {
      return console.log('error running query', err);
    }
    var jsonResult = JSON.stringify( result );
    console.log(">>> successful query. jsonResult: " +  jsonResult);
    client.end();
    return jsonResult;
  });
});

除了在">>试图连接..."之外,没有任何打印语句会出现在此代码中,我感到困惑.

I'm confused as to how no print statement, besides ">> trying to connect...," could show up in this code.

推荐答案

您应该检查两件事

  1. 请确保您的Lambda函数不会提前返回,您发布的代码片段不包含对context.done()的任何调用,因此很难知道您是否正确处理了此代码.您要在其他地方打context.done()吗?
  2. 您的Redshift集群是否可以访问互联网?当您手动连接到Redshift集群时,您是通过EC2实例还是通过Internet进行连接?如果是前者,则Lambda函数可能无法连接到群集,因为该群集不可寻址(但它来自您的EC2实例,因为您已将群集的安全组配置为允许该实例的安全组进行连接). 您可以阅读有关如何配置访问权限的更多信息到您的集群中.
  1. Make sure that your Lambda function doesn't return early, the snipplet you posted doesn't contain any call to context.done() so it's hard to know if you're handling this correctly. Are you calling context.done() somewhere else?
  2. Is your Redshift cluster open to the internet? When you connect to your Redshift cluster manually do you do it from an EC2 instance, or over the internet? If it's the former your Lambda function can probably not connect to the cluster because the cluster is not addressable (but it is from your EC2 instance because you've configured the cluster's security group to allow the instance's security group to connect). You can read more about how to configure access to your cluster here.

这篇关于尝试通过AWS Lambda连接到Redshift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆