def job_exec()

in src/invokepostgresqldbpy/invokepostgresqlproc.py [0:0]


def job_exec():

    # Get User's input via environment variable.
    secret_name = environ.get('secretname')
    region_name = environ.get('Region')

    global secret
    secret = getSecret(secret_name,region_name) # Connect to RDS DB using a secret stored in secretes manager.

    db_host=secret['host']
    db_user=secret['username']
    db_pwd=secret['password']
    db_name=secret['dbname']
    try:
        conn = psycopg2.connect(database=db_name, user=db_user,password=db_pwd, host=db_host)
        cur = conn.cursor()

        # Call function
        print('Calling  postgresql function concat_lower_or_upper')
        cur.callproc('concat_lower_or_upper', ('hello','world','true'))
        row = cur.fetchone()
        while row is not None:
            print(row)
            row = cur.fetchone()
    except (Exception, psycopg2.DatabaseError) as error :
        print ("Error while connecting to PostgreSQL", error)
    finally:
        #closing database connection.
        if(conn):
            cur.close()
            conn.close()
            print("PostgreSQL connection is closed")