1 Answer
- Newest
- Most votes
- Most comments
0
It depends on when init_database_dao() is being called. If it's called from the mainline of your code rather than the event handler then it will be called only when the Lambda's container is initialised. With provisioned concurrency that won't be very often - so during quiet times your database connection will time out and need to be refreshed.
Relevant content
- asked a year ago

It is called inside the handler method. The init_database_dao() is a static method and the class in which it is defined is imported from a different python package outside the handler . I have created reset_if_cursor_or_conn_is_none function to refresh the connection .
When init_database_dao() is called, either a fresh connection is created or old one's status is checked and if needed is reset .When i am getting SSL error while executing query (in my observation it comes when we are getting already created connection object) ,while calling init_database_dao() none of the condition mentioned in the if statement of reset_if_cursor_or_conn_is_none() is getting true and hence reset() is not executed. I am wondering if there is any other attribute whose value needs to be checked in case of db timeout etc.As per this https://stackoverflow.com/questions/1281875/making-sure-that-psycopg2-database-connection-alive , the closed attribute should be able to give info about connection open/close. Once I am getting SSL error, I am calling the reset() method in exception block and refreshing the connection. I want to check if any connection refresh is needed before executing any query (so that i don't encounter any Operational Error)