-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAWS_connection.py
More file actions
30 lines (22 loc) · 760 Bytes
/
Copy pathAWS_connection.py
File metadata and controls
30 lines (22 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import psycopg2
import logging as Logger
ENDPOINT="postgres.chcecoomgfvf.eu-west-1.rds.amazonaws.com"
PORT="5432"
USER="postgres"
REGION="us-west-1"
DBNAME="postgres"
def establish_connection():
try:
conn = psycopg2.connect(host=ENDPOINT, port=PORT, dbname=DBNAME, user=USER, password="Bitirme123",
sslmode='require')
conn.autocommit = True
cursor = conn.cursor()
return cursor
except (Exception, psycopg2.DatabaseError) as error:
Logger.raise_error(f"Error while connecting to PostgreSQL: {error}")
return None
if __name__ == "__main__":
cursor = establish_connection()
cursor.execute("Select * from citizen")
test = cursor.fetchall()
print(test)