I have a workspace that is writing to Google BigQuery and is connecting using the service account key file option. For this to work, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be set to the path of the key file. I have uploaded the file to my FME Cloud instance, but need to know how to set the environment variable.
How can I set the GOOGLE_APPLICATION_CREDENTIALS to the path to my service account key file in FME Cloud?
Best answer by takashi
Hi @bill.dollins , since the GoogleBigQueryConnector is implemented with Python, you can overwrite the environment variable at run-time with a PythonCaller inserted before the GoogleBigQueryConnector.
For example, a PythonCaller with this script will overwrite the environment variable by the full path of the key file which is saved in the folder where the workspace is saved.
import fme
import os
def setGoogleAppCredentialsEnviron(feature):
dir = fme.macroValues['FME_MF_DIR']
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = os.path.join(dir, 'your-key-file.json')
When publishing the workspace to the FME Server, upload the key file into the repository simultaneously. Alternatively you can also upload the key file individually into the repository through the FME Server Web Interface later. You can then run the workspace containing the GoogleBigQueryConnecter that uses the key file.
It works, however, I would recommend you to create and use a Web Connection rather than use a key file, due to security reason.
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.