Google容器引擎:访问云存储
Google Container Engine: Accessing Cloud Storage
我无法在 Google 容器引擎中使用应用程序默认凭据。文档说它们适用于 App Engine 和 Compute Engine,但我被告知它们应该透明地传递到 Container Engine 上的容器 运行。
这是失败的代码:
credentials = GoogleCredentials.get_application_default()
service = discovery.build('storage', 'v1', credentials=credentials)
失败的错误:AssertionError: No api proxy found for service "memcache"
期望应用程序默认凭据与容器引擎一起工作是否正确?如果没有,谁能推荐从 Container Engine 上的容器 运行 连接到云存储的正确方法?
谢谢。
编辑: 在 运行 gcloud beta auth application-default activate-service-account --key-file <my_key>.json
之后,上述 Python 示例中的 credentials
对象填充了数据。但是我仍然遇到同样的错误。
在 Container Engine 上访问云存储的最简单方法似乎是 gcloud 库。
如果 App Engine SDK 安装在容器上,它将无法使用零配置(gcloud 找到它并假定它在 App Engine 上 运行ning)。所以我停止使用官方Google container.
在 python container 上,只需将 gcloud 添加到您的 requirements.txt(或 运行 pip install gcloud
).只要容器存在于 Google Compute Engine 实例上,您就可以访问同一项目中的任何存储桶。
示例:
from gcloud import storage
client = storage.Client()
bucket = client.get_bucket('<bucket_name>')
blob = bucket.blob('test_file.txt')
blob.upload_from_string('test content')
我无法在 Google 容器引擎中使用应用程序默认凭据。文档说它们适用于 App Engine 和 Compute Engine,但我被告知它们应该透明地传递到 Container Engine 上的容器 运行。
这是失败的代码:
credentials = GoogleCredentials.get_application_default()
service = discovery.build('storage', 'v1', credentials=credentials)
失败的错误:AssertionError: No api proxy found for service "memcache"
期望应用程序默认凭据与容器引擎一起工作是否正确?如果没有,谁能推荐从 Container Engine 上的容器 运行 连接到云存储的正确方法?
谢谢。
编辑: 在 运行 gcloud beta auth application-default activate-service-account --key-file <my_key>.json
之后,上述 Python 示例中的 credentials
对象填充了数据。但是我仍然遇到同样的错误。
在 Container Engine 上访问云存储的最简单方法似乎是 gcloud 库。
如果 App Engine SDK 安装在容器上,它将无法使用零配置(gcloud 找到它并假定它在 App Engine 上 运行ning)。所以我停止使用官方Google container.
在 python container 上,只需将 gcloud 添加到您的 requirements.txt(或 运行 pip install gcloud
).只要容器存在于 Google Compute Engine 实例上,您就可以访问同一项目中的任何存储桶。
示例:
from gcloud import storage
client = storage.Client()
bucket = client.get_bucket('<bucket_name>')
blob = bucket.blob('test_file.txt')
blob.upload_from_string('test content')