55import json
66import logging
77import os
8- import cx_Oracle
8+ import oracledb
99
1010logger = logging .getLogger ()
1111logger .setLevel (logging .INFO )
@@ -49,6 +49,9 @@ def lambda_handler(event, context):
4949 KeyError: If the secret json does not contain the expected keys
5050
5151 """
52+ # Thick client to match full functionality of cx_oracle
53+ oracledb .init_oracle_client ()
54+
5255 arn = event ['SecretId' ]
5356 token = event ['ClientRequestToken' ]
5457 step = event ['Step' ]
@@ -234,7 +237,7 @@ def set_secret(service_client, arn, token):
234237 sql_commands = row [0 ].read ().strip (' \n \t ' ).replace ("%s" % escaped_current , "%s" % escaped_username )
235238 for sql_command in sql_commands .split ('\n ' ):
236239 cur .execute (sql_command )
237- except cx_Oracle .DatabaseError :
240+ except oracledb .DatabaseError :
238241 # If we were unable to find any grants skip this type
239242 pass
240243 conn .commit ()
@@ -321,7 +324,7 @@ def get_connection(secret_dict):
321324 secret_dict (dict): The Secret Dictionary
322325
323326 Returns:
324- Connection: The cx_Oracle object if successful. None otherwise
327+ Connection: The oracledb object if successful. None otherwise
325328
326329 Raises:
327330 KeyError: If the secret json does not contain the expected keys
@@ -332,12 +335,12 @@ def get_connection(secret_dict):
332335
333336 # Try to obtain a connection to the db
334337 try :
335- conn = cx_Oracle .connect (secret_dict ['username' ],
336- secret_dict ['password' ],
337- secret_dict ['host' ] + ':' + port + '/' + secret_dict ['dbname' ])
338+ conn = oracledb .connect (user = secret_dict ['username' ],
339+ password = secret_dict ['password' ],
340+ dsn = secret_dict ['host' ] + ':' + port + '/' + secret_dict ['dbname' ])
338341 logger .info ("Successfully established connection as user '%s' with host: '%s'" % (secret_dict ['username' ], secret_dict ['host' ]))
339342 return conn
340- except (cx_Oracle .DatabaseError , cx_Oracle .OperationalError ):
343+ except (oracledb .DatabaseError , oracledb .OperationalError ):
341344 return None
342345
343346
@@ -551,4 +554,4 @@ def get_connection_params_from_rds_api(master_dict, master_instance_arn):
551554 if master_dict ['engine' ] in ['oracle-ee' , 'oracle-ee-cdb' , 'oracle-se2' , 'oracle-se2-cdb' , 'custom-oracle-ee' ]:
552555 master_dict ['engine' ] = 'oracle'
553556
554- return master_dict
557+ return master_dict
0 commit comments