ASSOCIATE-CLOUD-ENGINEER · Question #253
You want your application hosted on a VM to fetch metadata of that instance. Which command will help you to fetch it?
The correct answer is C. curl metadata.google.internal/computeMetadata/v1/. To fetch metadata from a Google Cloud VM instance, applications should use the specific internal domain metadata.google.internal and the /computeMetadata/v1/ path with the appropriate Metadata-Flavor header.
Question
Options
- Acurl metadata.google.internal/compute-metadata/v1/
- Bcurl <instance-private-ip>/metadata/v1/
- Ccurl metadata.google.internal/computeMetadata/v1/
- Dcurl internal.googleapi.com/computeMetadata/v1/
How the community answered
(39 responses)- B3% (1)
- C95% (37)
- D3% (1)
Why each option
To fetch metadata from a Google Cloud VM instance, applications should use the specific internal domain `metadata.google.internal` and the `/computeMetadata/v1/` path with the appropriate `Metadata-Flavor` header.
The path `compute-metadata` with a hyphen is incorrect; the correct path uses camel case `computeMetadata`.
Directly querying the instance's private IP for metadata is not the standard or recommended method; the special internal DNS name `metadata.google.internal` is used.
The standard and recommended method for applications running on a Google Cloud VM to access instance metadata is to send a `curl` request to `http://metadata.google.internal/computeMetadata/v1/`, including the `Metadata-Flavor: Google` header.
The domain `internal.googleapi.com` is used for other internal Google APIs, not specifically for fetching instance metadata from a VM itself.
Concept tested: Accessing Google Cloud instance metadata
Source: https://cloud.google.com/compute/docs/storing-retrieving-metadata#default
Topics
Community Discussion
No community discussion yet for this question.