I ran the below python snippet using python-snowflake-connector, with the below environment variables, from an AWS lambda:
Env vars (I don't think they are documented, but I found them in the source code) :
# NOTE : running below with OCSP mode set to : Fail Close
with snowflake.connector.connect(**snowflake_connection_parameters) as connection:
cursor = connection.cursor(DictCursor)
cursor.execute("SELECT 1 as N FROM dual", {})
return cursor.fetchall()
What did you expect to see?
I was expecting to see no failure in the DEBUG logs and to have caches dumped to files.
However, the DEBUG logs show that although I would like to have my cache under the /tmp folder, the connector still attempts to write some cache to my home folder. As I run on a AWS lambda, my /home/<user> file system is not writeable, it's a readonly system. The connector will then fallback to using in memory caches here, but I'd prefer writing to files as a benchmark I did makes the connection initialisation faster.
Tested locally with a draft change to the source code : If we introduce an env var, such as the one used above, e.g. SF_OCSP_RESPONSE_VALIDATION_CACHE_DIR and set it to a writable path, and use it when building the file_path dict pointed to above, then the issue disappear and we use SFDictFileCaches as expected.
Being able to specify cache directories on lambda environments makes the lambdas execution faster.
Can you set logging to DEBUG and collect the logs?
(Username and links obfuscated)
Python 3.10.9
Linux-5.4.0-1100-aws-x86_64-with-glibc2.27
pip freeze
)?I ran the below python snippet using
python-snowflake-connector
, with the below environment variables, from an AWS lambda: Env vars (I don't think they are documented, but I found them in the source code) :Python snippet
I was expecting to see no failure in the DEBUG logs and to have caches dumped to files. However, the DEBUG logs show that although I would like to have my cache under the
/tmp
folder, the connector still attempts to write some cache to my home folder. As I run on a AWS lambda, my/home/<user>
file system is not writeable, it's a readonly system. The connector will then fallback to using in memory caches here, but I'd prefer writing to files as a benchmark I did makes the connection initialisation faster.By looking at the code here : https://github.com/snowflakedb/snowflake-connector-python/blob/main/src/snowflake/connector/ocsp_snowflake.py#L85 The path where we want to write to, for the OCSP validation cache, is hardcoded and there's no way to customise this path.
Tested locally with a draft change to the source code : If we introduce an env var, such as the one used above, e.g.
SF_OCSP_RESPONSE_VALIDATION_CACHE_DIR
and set it to a writable path, and use it when building the file_path dict pointed to above, then the issue disappear and we useSFDictFileCache
s as expected.Being able to specify cache directories on lambda environments makes the lambdas execution faster.