Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13891

Implications of querying database before lambda_handler

$
0
0

Here is the pseudo-code for what current lambda function looks like;

import pandasimport pymysqldef get_db_data(con_):    query = "SELECT * FROM mytable"    data = pandas.read_sql(query, con_)    return datadef lambda_handler(event, context):    con = pymysql.connect()    data = get_db_data(con)"""    do other things with event"""    con.close()

I am debating if I can do this instead:

import pandasimport pymysqlcon = pymysql.connect()def get_db_data(con_):    query = "SELECT * FROM mytable"    data = pandas.read_sql(query, con_)    return datadata = get_db_data(con)def lambda_handler(event, context):"""    do other things with event"""    con.close()

But I am not sure if it is a good practice. What implications would the second option have on run-time and cost? Is it against the recommended way?


Viewing all articles
Browse latest Browse all 13891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>