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 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南