从 gcloud ml-engine 作业访问 Big Query
Access from gcloud ml-engine jobs to Big Query
我有一个 python ML 进程,它使用环境变量 GOOGLE_APPLICATION_CREDENTIALS
指向的本地 json
文件连接到 BigQuery
(该文件包含我的密钥由 google 提供,参见 authentication getting-started )
当 运行 在本地运行时效果很好。
我现在希望通过 Google's Ml engine 部署我的模型,特别是使用 shell 命令 gcloud ml-engine jobs submit training
。
但是,在我 运行 我的进程并查看 console.cloud.google.com/logs/viewer
中的日志后,我看到 gcloud 无法访问 Bigquery
并且我收到以下错误:
google.auth.exceptions.DefaultCredentialsError: File:
/Users/yehoshaphatschellekens/Desktop/google_cloud_xgboost/....-.....json was not found.
目前我不认为 gcloud ml-engine jobs submit training
带有 Json 文件(我认为 gcloud 可以自动访问 BigQuery,我猜不是)
一个可选的解决方法是将我的个人 .json 保存到另一个子包文件夹中的 python 依赖项中(参见 packaging-trainer)并导入它。
这个解决方案可行/安全吗?
这个问题还有其他解决方法吗?
路径应该是绝对路径并且在 Windows:
中带有反斜杠
GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\[FILE_NAME].json"
在您的 Python 代码中这样设置:
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "C:\PATH.JSON"
示例 Google 翻译 API here。
我最终所做的是将 json 上传到 gcloud
存储桶,然后在每次启动 ML-engine 训练过程时将其上传到我的项目中:
os.system('gsutil cp gs://secured_bucket.json .')
os.environ[ "GOOGLE_APPLICATION_CREDENTIALS"] = "......json"
我有一个 python ML 进程,它使用环境变量 GOOGLE_APPLICATION_CREDENTIALS
指向的本地 json
文件连接到 BigQuery
(该文件包含我的密钥由 google 提供,参见 authentication getting-started )
当 运行 在本地运行时效果很好。
我现在希望通过 Google's Ml engine 部署我的模型,特别是使用 shell 命令 gcloud ml-engine jobs submit training
。
但是,在我 运行 我的进程并查看 console.cloud.google.com/logs/viewer
中的日志后,我看到 gcloud 无法访问 Bigquery
并且我收到以下错误:
google.auth.exceptions.DefaultCredentialsError: File:
/Users/yehoshaphatschellekens/Desktop/google_cloud_xgboost/....-.....json was not found.
目前我不认为 gcloud ml-engine jobs submit training
带有 Json 文件(我认为 gcloud 可以自动访问 BigQuery,我猜不是)
一个可选的解决方法是将我的个人 .json 保存到另一个子包文件夹中的 python 依赖项中(参见 packaging-trainer)并导入它。
这个解决方案可行/安全吗?
这个问题还有其他解决方法吗?
路径应该是绝对路径并且在 Windows:
中带有反斜杠GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\[FILE_NAME].json"
在您的 Python 代码中这样设置:
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "C:\PATH.JSON"
示例 Google 翻译 API here。
我最终所做的是将 json 上传到 gcloud
存储桶,然后在每次启动 ML-engine 训练过程时将其上传到我的项目中:
os.system('gsutil cp gs://secured_bucket.json .')
os.environ[ "GOOGLE_APPLICATION_CREDENTIALS"] = "......json"