从 AWS Lambda 连接到 Redshift [英] Connect to Redshift from AWS Lambda

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

问题描述

我正在尝试从我的 AWS Lambda 函数连接到我的 Redshift 数据库:

I'm trying to connect to my Redshift database from my AWS Lambda function:

con = psycopg2.connect(
    dbname="my_dbname",
    host="my_url",
    port= 5439,
    user="username",
    password="my_password")

cur = con.cursor()

但是我无法访问我的数据库,我的函数引发了以下错误:

But I can't access my database, my function raises the following error:

OperationalError: could not connect to server: Connection timed out
    Is the server running on host "my_url" (54.217.83.88) and accepting
    TCP/IP connections on port 5439?

我能得到一些帮助吗?(如果可能的话,我想要一个非常详细的答案,因为我是 AWS 的新手)

Can i get some help with this please ? (and if possible I'd like to have a very detailed answer, because I'm new to AWS )

PS:我知道我必须配置VPC,但我不知道具体要做什么

PS: I know that I have to configure the VPC, but I don't know what to do exactly

提前致谢

推荐答案

您的目标是让 AWS Lambda 函数通过私有 IP 地址与同一 VPC 内的 Amazon Redshift 集群进行通信.这会将流量保持在 VPC 内.

Your goal is to have the AWS Lambda function communicate with the Amazon Redshift cluster within the same VPC, via private IP address. This keeps the traffic within the VPC.

  • AWS Lambda 函数需要配置为连接到与 Amazon Redshift 集群位于同一 VPC 中的私有子网.
  • The AWS Lambda function will need to be configured to connect to a private subnet in the same VPC as the Amazon Redshift cluster.

请参阅:配置 Lambda 函数以访问 Amazon VPC 中的资源

  • Either connect to the Private IP address of the cluster or (preferably) follow the directions on Managing Clusters in an Amazon Virtual Private Cloud (VPC) to enable DNS Hostnames and DNS Resolution on the VPC so that the host name will automatically resolve to the Private IP address.

与 Amazon Redshift 集群关联的安全组需要允许来自 VPC 的 CIDR 范围(或视情况而定)的端口 5439 上的入站流量.

The Security Group associated with the Amazon Redshift cluster will need to permit inbound traffic on port 5439 from the CIDR range of the the VPC (or as appropriate).

请参阅:Amazon Redshift 集群安全组

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

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