Unable to connect to postgres Cluster from python-Shell Script

0

Hello All,

I have created simple python-shell script as mentioned below code is running fine from my local system and I am also able to connect to cluster from my local system.

But when try running python-shell script as glue then getting following error:

import sys
import psycopg2


rds_host  = "hostname"
name = "aaaaaaa"
password = "XXXXXXX"
db_name = "bbb"
conn = psycopg2.connect(host=rds_host, user=name, password=password, dbname=db_name)

with conn.cursor() as cur:
   query="CALL test_vals()"
   cur.execute(query)
   conn.commit()
   cur.close()

cloudwatch error log

    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection timed out
	Is the server running on host "hostname" (XX.XXX.XX.XX) and accepting
	TCP/IP connections on port 5432?


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/runscript.py", line 215, in <module>

I have not added any Connections in job properties .

Please help .

質問済み 1年前447ビュー
1回答
1

Hi , the right answer depends on the configuration of the PostgreSQL database. is it hosted in a subnet (AWS VPC or on Prem) which is accessible via the internet? Do you have a firewall or a security group configured limiting access to a some CIDR ranges?

Without connection (not even a Network connection) the Glue Job would run outside a VPC so it may not have the right route to your cluster or it could be blocked by the Security Group/Firewall.

So, you need to use Connection (even a network connection ) it makes the glue job run in your VPC and thus easily define the right routing or setting for the Security Group. Please review the documentation here.

hope this helps

AWS
エキスパート
回答済み 1年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ