从AWS Glue连接到Postgres Heroku数据库时遇到SSL问题

3

我正在尝试连接到我的Heroku数据库,但是我遇到了与SSL相关的以下一系列错误:

SSL connection to data store using host matching failed. Retrying without host matching.
SSL connection to data store failed. Retrying without SSL.
Check that your connection definition references your JDBC database with correct URL syntax, username, and password. org.postgresql.util.PSQLException: Connection attempt timed out.

我成功使用 DBeaver 连接到了数据库,并且在设置 SSL Factory 为 org.postgresql.ssl.NonValidatingFactory之前也遇到了类似的 SSL 问题,但是 Glue 没有提供任何 SSL 选项。

实际上,该数据库托管在 AWS 上,连接 URL 是:

jdbc:postgresql://ec2-52-19-160-2.eu-west-1.compute.amazonaws.com:5432/something

(p.s. AWS Glue论坛没什么用!他们似乎不回答任何人的问题)


你解决过这个问题吗?我也在尝试从AWS Glue连接到我的Heroku Postgres数据库,但遇到了相同的问题。 - Bryan Cosgrove
不,事实证明你需要使用SSL连接到Heroku的Postgres数据库,但是当我发布这篇文章时,Glue并没有提供此功能。AWS支持表示这在待办列表中。我放弃了Glue,现在使用Step Functions进行所有AWS编排。更加简单。 - CpILL
1个回答

1
我遇到了同样的问题,看起来问题在于Heroku需要比Amazon要求的更高版本的JDBC驱动程序。请参考此主题:使用Heroku数据库的AWS数据管道 此外,似乎您可以直接从Python脚本中使用jbdc。请参见此处:

https://dzone.com/articles/extract-data-into-aws-glue-using-jdbc-drivers-and

看起来你需要下载一个新的驱动程序,将其上传到S3,然后像这里提到的那样手动在你的脚本中使用它:

https://gist.github.com/saiteja09/2af441049f253d90e7677fb1f2db50cc

祝你好运!

更新:我能够在Glue Job中使用以下代码片段连接到数据。我必须将Postgres驱动程序上传到S3,然后将其添加到我的Glue Job的路径中。此外,请确保Jars要么是公共的,要么已经配置了IAM用户的策略,以便他们可以访问存储桶。

%pyspark
import sys
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.dynamicframe import DynamicFrame
from awsglue.transforms import *

glueContext = GlueContext(SparkContext.getOrCreate())

source_df = spark.read.format("jdbc").option("url","jdbc:postgresql://<hostname>:<port>/<datbase>“).option("dbtable", “<table>”).option("driver", "org.postgresql.Driver").option("sslfactory", "org.postgresql.ssl.NonValidatingFactory").option("ssl", "true").option("user", “<username>”).option("password", “<password>”).load()

dynamic_dframe = DynamicFrame.fromDF(source_df, glueContext, "dynamic_df")

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接