Question

I have several Google Compute Engine instances, and have set instance metadata on each, under the assumption these are available on the instance itself as an environment variable, but they don't show up. I then read here that I need to query the metadata server for this data, but that just returns a 403 unauthorized when run from the instance itself. Is there a way to access metadata as environment variables?

Was it helpful?

Solution

It may be worth studying Metadata querying a bit more, but my guess is that you are attempting to get custom metadata, which is resulting in it not being found. Make sure you are using the attributes directory to access any custom metadata.

For example, this will get the built-in tags metadata:

curl "http://metadata.google.internal/computeMetadata/v1/instance/tags" \
    -H "Metadata-Flavor: Google"

while this will get your custom metadata for attribute foo:

curl "http://metadata.google.internal/computeMetadata/v1/<instance|project>/attributes/foo" \
    -H "Metadata-Flavor: Google"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top