【发布时间】:2020-10-12 13:45:33
【问题描述】:
我正在尝试通过 lambda 使用 python 连接到 redshift。目的是对redshift数据库进行查询。
我已经通过获取临时 aws 凭据并连接到 psycopg2 来尝试 this,但没有任何错误消息就无法成功。 (即:lambda 刚刚超时)
rs_host = "mytest-cluster.fooooooobaaarrrr.region111111.redshift.amazonaws.com"
rs_port = 5439
rs_dbname = "dev"
db_user = "barrr_user"
def lambda_handler(events, contx):
# The cluster_creds is able to be obtained successfully. No issses here
cluster_creds = client.get_cluster_credentials(DbUser=db_user,
DbName=rs_dbname,
ClusterIdentifier="mytest-cluster",
AutoCreate=False)
try:
# It is this psycopg2 connection that cant work...
conn = psycopg2.connect(host=rs_host,
port=rs_port,
user=cluster_creds['DbUser'],
password=cluster_creds['DbPassword'],
database=rs_dbname
)
return conn
except Exception as e:
print(e)
此外,lambda 执行角色本身具有以下策略:
我不知道为什么我仍然无法通过 python 连接到 redshift 来执行查询。
我也尝试过使用 sqlalchemy 库,但没有运气。
【问题讨论】:
-
可能是网络问题。您的 Redshift 安全组是否对运行 Lambda 函数的位置开放?
-
嗨,乔纳森,对不起,你这是什么意思?您是在询问 redshift 集群权限是否附加了 IAM 角色?
-
不,我是问你是否从网络角度打开了集群:docs.aws.amazon.com/redshift/latest/mgmt/…
-
是的,你是对的。我的 VPC 附加到的安全组...我使用的是默认值,默认情况下,所有内容都被阻止。谢谢!