May-03-2019, 04:41 AM
OK here is my full code
Before worrying about the error message. 1st question would be if i have the correct format for line 23
Then next question would be if I have it in the right place.
I am using the Official Python Connector for MySQL.
Thanks in advance.
Before worrying about the error message. 1st question would be if i have the correct format for line 23
Then next question would be if I have it in the right place.
I am using the Official Python Connector for MySQL.
Thanks in advance.
import os import sys import logging sys.path.insert(0, '/opt') import json import mysql.connector logger = logging.getLogger() logger.setLevel(logging.INFO) logger.info("SUCCESS: Connection to DB instance succeeded") def lambda_handler(event, context): cnx = mysql.connector.connect(user=os.environ['user'], database=os.environ['database'], host=os.environ['host'], password=os.environ['password']) cursor = cnx.cursor() query = ("SELECT distinctrow UPC, ItemFriendlyNames, ItemName, Brand, Model, Retailer, ItemID FROM my.view order by UPC, Model, Retailer") cursor.execute(query) rows = cursor.fetchall() json_rows = [dict(zip(('UPC', 'ItemFriendlyNames', 'ItemName', 'Brand', 'Model', 'Retailer', 'ItemID'), (str(key), value, value, value, value, value, value))) for key, value in rows] cursor.close() cnx.close() return { 'statusCode': 200, 'headers': {'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json'}, "body": json.dumps(rows) }