Instance environment variables

走远了吗. 提交于 2019-12-20 17:43:21

问题


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?


回答1:


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"


来源:https://stackoverflow.com/questions/23376214/instance-environment-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!