Simplifying my program, I have a MySQL RDS DB, and I want to develop a Lambda function to get the last value inserted in a specific column.
I have got the following code in a lambda function, based on this AWS tutorial:
# Connexion to DB outside the handler, per AWS recomendation
def lambda_handler(event, context):
with conn.cursor() as cur:
cur.execute("SELECT column FROM DB.table ORDER BY create_time DESC LIMIT 1;")
row = cur.fetchone()
return row[0]
I am using pymysql
.
Basically, in the first call (after saving the lambda function, for example) it works as supposed to, and it returns the last value in the table.
However, for any other call during a short interval (some minutes), it continues to return the same value, independent of any DB changes.
Saving or Waiting for some minutes leads to the correct result. Is it possible that I'm unintentionally caching the result?