是否可以在 Google Collaboratory 上获取 GCP 的实例元数据?

Is it possible to obtain instance metadata for GCP on Google Collaboratory?

我正在尝试获取 Google Collaboratory 上的实例元数据。我有兴趣找出计算区域。

具体来说,在 Google Collaboratory 上的托管运行时,我尝试了 运行 以下命令,但它们超时了。

!curl "http://metadata.google.internal/computeMetadata/v1/?recursive=true&alt=json" -H "Metadata-Flavor: Google"

curl: (7) Failed to connect to metadata.google.internal port 80: Connection timed out
!curl "http://169.254.169.254/computeMetadata/v1/instance/?recursive=true&alt=json" -H "Metadata-Flavor: Google"

curl: (7) Failed to connect to 169.254.169.254 port 80: Connection timed out

是我做错了什么,还是有其他解决方法?

谢谢!

您无法从 Google 云平台外部访问元数据服务器,因为它是 Google 计算引擎 (GCE) 的特定内容。

为了知道计算区域,您可以 link 将您的 Google 协作笔记本与 GCE 中的实例 VM 放在一起,然后您的笔记本将 运行 在该特定实例 VM 中.

另一种方法是使用 AI platform notebooks 而不是 Google Collaboratory,因为它使用 GCE 作为后端。