INNER CODE UNIT · Python
get_snowflake_connection
ElizaLo/NLP-Natural-Language-Processing · Data Analysis/db_utils.py:20
def get_snowflake_connection(secret_name, warehouse, database, schema):
snowflake_secret = get_secret(secret_name)
ctx = snowflake.connector.connect(
user=snowflake_secret['username'],
password=snowflake_secret['password'],
account=snowflake_secret['accountname'],
ocsp_response_cache_filename='/tmp/ocsp_response_cache'
)
ctx.execute_string("USE WAREHOUSE {};".format(warehouse), return_cursors=False)
ctx.execute_string("USE DATABASE {};".format(database), return_cursors=False)
ctx.execute_string("USE SCHEMA {};".format(schema), return_cursors=False)
return ctx