从 AWS Lambda 连接到 Redshift [英] Connect to Redshift from AWS Lambda
问题描述
我正在尝试从我的 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 中的资源
连接到集群的私有 IP 地址,或者(最好)按照 管理 Amazon Virtual Private Cloud (VPC) 中的集群 以启用
DNS Hostnames
和DNS在 VPC 上解析
,以便主机名自动解析为私有 IP 地址.
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
andDNS 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).
这篇关于从 AWS Lambda 连接到 Redshift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!