forked from alexanderluiscampino/lambda-layers
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrds_connector.py
34 lines (28 loc) · 1.1 KB
/
rds_connector.py
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
31
32
33
34
import os
import pyodbc
class RDS(object):
username = os.getenv('USERNAME')
password = os.getenv('PASSWORD')
host = os.getenv('HOST')
port = os.getenv('PORT')
driver = os.getenv('DRIVER')
def __init__(self, database: str):
self.establish_connecion_string(database)
def establish_connecion_string(self, database):
def edit(string):
remove = ['\t', '\n']
for char in remove:
string = string.replace(char, ' ')
return string.replace(' ', '')
self.connection = edit(f"""DRIVER={{{self.driver}}};
Server={self.host};
PORT={self.port};
Database={database};
UID={self.username};
PWD={self.password};
ColumnEncryption=Enabled;
"""
)
rds = RDS(database)
connexion = pyodbc.connect(rds.connection)
# Proceed to use connexion to run a query against the database