0

I added a few, I'm not sure if any more would be useful. Also, is this all I have to do to write a lambda? I was given very little instruction on how to do it. It returns the result from the query like it's supposed to. I don't see anything wrong with it except for adding some logging exceptions?

import logging
import os
import sys
import mariadb as mdb

cnxn = mdb.connect(
user="username",
password="pass",
host="host",
port=port,
database="database"
)

cur=cnxn.cursor()
SQL_QUERY="CALL STORED_PROCEDURE();"
cur.execute(SQL_QUERY)
row=cur.fetchone()

def name_of_handler(event=None, context=None):
    try:
        cur.execute(SQL_QUERY)
        cnxn.commit()
    except mdb.Error as e:
        print(f"Error: {e}")
    except Exception as e:
        logging.exception(e)

    print(row)
    cnxn.close()

name_of_handler()

UPDATE: Nevermind, how do I write a message saying "executed successfully?" I see the records did insert into the database, but there is no confirmation in the python code.

9
  • Where in your code do you have a lambda? Commented Jan 26, 2023 at 22:15
  • the function is the lambda function. it's the "name_of_handler", which is the lambda handler Commented Jan 26, 2023 at 22:24
  • That's not a lambda, that's just a regular function. Commented Jan 26, 2023 at 22:26
  • Not a lambda... Commented Jan 26, 2023 at 22:28
  • oh! how do i make it a lambda? Commented Jan 26, 2023 at 22:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.