实例环境变量 [英] Instance environment variables

查看:87
本文介绍了实例环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个Google Compute Engine实例,并且在每个实例上都设置了实例元数据,假设这些实例元数据可以作为环境变量在实例本身上使用,但不会显示.然后,我在此处阅读,我需要在元数据服务器中查询该数据,但是当返回403未授权时,从实例本身运行.有没有办法将元数据作为环境变量访问?

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?

推荐答案

可能值得研究元数据查询要多一些,但是我的猜测是您正在尝试获取自定义元数据,这导致找不到它.确保使用attributes目录访问任何自定义元数据.

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.

例如,这将获取内置的tags元数据:

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

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

,这将获取属性foo的自定义元数据:

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"

这篇关于实例环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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