Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instance environment variables

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?

like image 920
regretoverflow Avatar asked Apr 29 '14 22:04

regretoverflow


People also ask

Where are AWS environment variables?

To set environment variables Sign in to the AWS Management Console and open the Amplify console . In the Amplify console, choose App Settings, and then choose Environment variables. In the Environment variables section, choose Manage variables. In the Manage variables section, under Variable, enter your key.

What is meant by environment variables?

An environment variable is a variable whose value is set outside the program, typically through functionality built into the operating system or microservice. An environment variable is made up of a name/value pair, and any number may be created and available for reference at a point in time.

How can I see all environment variables?

To list all the environment variables, use the command " env " (or " printenv "). You could also use " set " to list all the variables, including all local variables.

What is the purpose of environment variables?

An environment variable is a dynamic "object" on a computer, containing an editable value, which may be used by one or more software programs in Windows. Environment variables help programs know what directory to install files in, where to store temporary files, and where to find user profile settings.


1 Answers

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"
like image 179
Christopher Wirt Avatar answered Oct 09 '22 09:10

Christopher Wirt