从 AWS Lambda 连接到 Redshift

2024-03-18

我正在尝试连接到我的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,但我不知道具体该怎么做

提前谢谢你


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

  • The AWS Lambda需要将函数配置为连接到与 Amazon Redshift 集群位于同一 VPC 中的私有子网。

See: 配置 Lambda 函数以访问 Amazon VPC 中的资源 https://docs.aws.amazon.com/lambda/latest/dg/vpc.html

  • 要么连接到私有IP地址集群的或(最好)遵循管理 Amazon Virtual Private Cloud (VPC) 中的集群 https://docs.aws.amazon.com/redshift/latest/mgmt/managing-clusters-vpc.html启用DNS Hostnames and DNS Resolution在 VPC 上,以便主机名将自动解析为私有 IP 地址。

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

See: Amazon Redshift 集群安全组 https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-security-groups.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 AWS Lambda 连接到 Redshift 的相关文章

随机推荐