Thanks to Noels answer, I was facing similar issue where API GW was using lambda(python runtime) functions(with api gw cache disabled).The problem was that i defined the db connection outside the lambda handler. The result of the code below was old data(even after database table updates) from api.
db = pymysql.connect(host=DB_HOST,user=DB_USER, password=DB_PSWD,database=DB_NAME,cursorclass=pymysql.cursors.DictCursor)
cursor = db.cursor()
def lambda_handler(event, context):
try:
cursor.execute("SELECT id, product FROM repository")
return { "body":json.dumps(cursor.fetchall()), "statusCode":200}
except Exception as e:
return { "body":json.dumps(event), "statusCode":500}
To fix this i moved the db connection inside lambda handler:
def lambda_handler(event, context):
db = pymysql.connect(host=DB_HOST,user=DB_USER, password=DB_PSWD,database=DB_NAME,cursorclass=pymysql.cursors.DictCursor)
cursor = db.cursor()
try:
cursor.execute("SELECT id, product FROM repository")
return { "body":json.dumps(cursor.fetchall()), "statusCode":200}
except Exception as e:
return { "body":json.dumps(event), "statusCode":500}