Feb-18-2019, 10:42 AM
Hi,
My use case is to query a MySQL database as part of a (AWS) Lambda function that returns results in json format via an api. Queries may be selects, selects with variables, or firing sp's.
My current situation is I have a working example that I think is quite old. In addition im note sure that the output is in the correct json format. An example from the api is
.idea
_pycache_
pip
pip-9.0.1.dist-info
pkg_resources
pymysql
PyMySQL-0.7.11.dist-info
setuptools
setuptools-36.6.0.dist-info
wheel
wheel-0.30.0.dist.info
With Lambda there is the ability to run Python 3.7
Thanks for any assistance, greatly appreciated.
My use case is to query a MySQL database as part of a (AWS) Lambda function that returns results in json format via an api. Queries may be selects, selects with variables, or firing sp's.
My current situation is I have a working example that I think is quite old. In addition im note sure that the output is in the correct json format. An example from the api is
Output:[[""], ["Adelaide"], ["Alexandria"], ["Alice Springs"]]My current code is def handler(event, context):
try:
conn = pymysql.connect(rds_host, user=name, passwd=password, db=db_name, connect_timeout=20)
except:
logger.error("ERROR: Unexpected error: Could not connect to MySql instance.")
"""
This function fetches content from mysql RDS instance
"""
rows = []
with conn.cursor() as cursor:
sql = "SELECT * FROM tablea"
cursor.execute(sql)
for row in cursor:
rows.append(row)
print(row)
return {
'statusCode':200,
'headers': {'Access-Control-Allow-Origin': '*'},
'body': json.dumps(rows)
}The folders in my project are (im not even sure how to update).idea
_pycache_
pip
pip-9.0.1.dist-info
pkg_resources
pymysql
PyMySQL-0.7.11.dist-info
setuptools
setuptools-36.6.0.dist-info
wheel
wheel-0.30.0.dist.info
With Lambda there is the ability to run Python 3.7
Thanks for any assistance, greatly appreciated.
