是否从Google Compute Engine计算机检索项目ID? [英] Retrieve project id from Google Compute Engine machine?

查看:0
本文介绍了是否从Google Compute Engine计算机检索项目ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Google Cloud Platform项目(试运行和生产)。我希望我的应用程序部署在Google Compute Engine实例上,以自动检测项目ID。怎样才能做到这一点?

推荐答案

您可以通过编程方式查询metadata server中的各种信息,包括项目ID。

对于项目ID:

$ curl "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google"

这将返回您的项目ID,例如:my-gcp-project

或者如果您需要数字项目ID:

$ curl "http://metadata.google.internal/computeMetadata/v1/project/numeric-project-id" -H "Metadata-Flavor: Google"

这将返回数字项目ID,例如:0123456789

这篇关于是否从Google Compute Engine计算机检索项目ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆