2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GCEインスタンス内からProjectIDなどを取得する

2
Posted at

概要

GAEでは環境変数としてProjectIDがとってこれるけど、
GCEインスタンス内でProjectIDなどを取得するにはどうすればいいか。
やり方は簡単。GCEのメタデータサーバからcurlとかでリクエストなげてとってくる。

GCEのメタデータサーバとは

プロジェクト内のGCEのインスタンスすべてのメタデータを格納しているサーバで、GCEインスタンス内や ComputeEngineAPIから問い合わせることができます。
インスタンス内から問い合わせる場合は認証は必要なく、curlなどを使用してAPIを叩いて特定の情報を取得することができます。

メタデータサーバからProjectIDを取得するには

ヘッダに Metadata-Flavor: Google を入れて取得用のエンドポイントを叩きます。

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

参考

project-id以外も取得できます。以下を参考にしてください。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?