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 .

gefragt vor einem Jahr447 Aufrufe
1 Antwort
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
EXPERTE
beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen