从 AWS Glue 连接到 Postgres Heroku DB,SSL 问题



我正在尝试连接到我的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 工厂设置为org.postgresql.ssl.NonValidatingFactory之前遇到了类似的 SSL 问题,但 Glue 不提供任何 SSL 选项。

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

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

(附言AWS胶水论坛没用!他们似乎没有回答任何人的问题(

我遇到了同样的问题,似乎问题是 Heroku 需要比亚马逊需要的更新的 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

祝你好运!

更新:我能够在粘附作业中使用以下代码片段来连接到数据。我必须将 Postgres 驱动程序上传到 S3,然后将其添加到我的 Glue Job 的路径中。此外,请确保 Jar 是公有的,或者您已配置 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")

最新更新