I have a usecase that needs to update an onprem table using the aws glue python shell. Please note i want to use python-oracledb in thin mode
To my understanding it shouldnt look for the "tnsnames.ora" as i am using jdbc url . what is the way to look for the code to utilize the thin url below is the code i had written. Any suggestions or errors please let me know
import sys
import boto3
import oracledb
import ast
# Oracle connection details using Easy Connect string
session = boto3.session.Session()
client = session.client(service_name='secretsmanager')
def get_secret(secret_name):
# Create a Secrets Manager client
try:
get_secret_value_response = client.get_secret_value(SecretId=secret_name)
return get_secret_value_response
except Exception as e:
raise
def update_table(table_name):
try :
print("im here update table")
cred=get_secret("my_secret")
cred=ast.literal_eval(cred["SecretString"])
print(f"credentials {cred}")
user =cred["username"]
password =cred["password"]
conn_str = 'jdbc:oracle:thin://@my_host:my_port/my_service'
conn = oracledb.connect(user=user, password=password,dsn=conn_str)
cursor = conn.cursor()
cursor.execute("UPDATE my_table SET flag ='N' WHERE column ='xyz'")
conn.commit()
cursor.close()
conn.close()
return {
'statusCode': 200,
'body': json.dumps('Update successful')
}
except Exception as e:
raise
if __name__ == '__main__':
return_code = update_table("my_table")
Python is not Java and the connection strings differ. See the python-oracledb doc JDBC and Oracle SQL Developer Connection Strings for how to map JDBC connection strings into something usable by python-oracledb.
You almost certainly want to use:
conn_str = 'my_host:my_port/my_service'