首页 > 解决方案 > 使用 Docker 和 GCloud Python API 访问 GS,无需 VM 上的服务帐户

问题描述

我需要从运行在 VM 中的 Docker 映像访问 Google Storage。我在没有服务帐户(安全原因)的情况下运行 VM,并启动安装了 GCloud Python API 的 Docker 映像。当我尝试在 GS 上连接时,在我的情况下读取一些原始数据时,它抛出了这个异常:

Failed to retrieve http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/?recursive=true from the Google Compute Engine metadata service. Status: 404

当我使用服务帐户启动 VM 时,我可以成功调用使用 GCP Python API。

代码不起作用的示例:

from google.cloud import storage client = storage.Client() for bucket in client.list_buckets(): print(bucket)

有人已经面临这个问题了吗?是否可以在没有服务帐户的情况下使用 GCP Python?

[Pyhton 库] https://google-cloud-python.readthedocs.io/en/latest/storage/client.html

谢谢,

标签: pythondockergoogle-cloud-platform

解决方案


推荐阅读