从AWS Lambda连接到Redshift

时间:2018-04-04 14:53:29

标签: python amazon-s3 aws-lambda amazon-redshift

我尝试从我的Redshift功能连接到我的AWS Lambda数据库:

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

cur = con.cursor()

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

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的新手)

PS:我知道我必须配置VPC,但我不知道该怎么做

提前谢谢你

1 个答案:

答案 0 :(得分:0)

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

  • AWS Lambda 功能需要配置为连接到与Amazon Redshift群集相同的VPC中的私有子网。

请参阅:Configuring a Lambda Function to Access Resources in an Amazon VPC

  • 连接到群集的私有IP地址或(最好)按照Managing Clusters in an Amazon Virtual Private Cloud (VPC)上的说明启用DNS HostnamesDNS Resolution VPC,以便主机名自动解析为私有IP地址。

  • 与Amazon Redshift群集关联的安全组将需要允许来自VPC的CIDR范围(或适当时)的端口5439上的入站流量。

    < / LI>

请参阅:Amazon Redshift Cluster Security Groups