2022-02-25 14:40:34
Instance metadata is the basic information of a virtual machine instance, including instance id, intranet/external network IP address, etc. You can view the metadata of the instance by accessing the metadata service in the virtual machine, so as to perform internal configuration of the instance or to connect the instance with external applications for certain metadata.
To obtain metadata, you must first log in to the instance, and then access the instance. For details on logging in to an instance, please refer to Login to a Linux Instance and Login to a Windows Instance.
Obtaining metadata in an instance does not require any adjustment to the security group or network ACL. As long as you have the permission to log in to the instance, you can obtain metadata. In addition, if you modify some attribute such as password, key, and hostname within the instance, such changes will not be updated to the metadata, which may cause the query result to be inconsistent with the actual data.
JD Cloud now supports the following instance metadata queries:
Metadata Item | Description | Return Sample |
---|---|---|
pin | the pin of the instance user | "abcdabdc" |
instance-id | Instance ID | "i-abcdefg123" |
instance-type | instance specification | "g.n3.large" |
instance-name | Instance name | "jdcloud-instance" |
description | Instance description | "JD virtual machine" |
attributes/ssh-keys | instance-associated key and public key | "c3NoLXJzYSBBQUFBQ..p2aXJ0" |
attributes/activation/KMS | KMS server address, only be returned for windows | "169.254.169.250:1688" |
attributes/hostname | instance hostname | "jdcloud-server.internal" |
placement/region | instance region | "cn-north-1" |
placement/availability-zone | instance availability zone | "cn-north-1c" |
image/image-id | Image ID used to create the instance | "img-ix4782iy3c" |
image/os-type | instance OS type | "linux" |
network/[serial-no] / | the attribute directory of the instance network interface [serial-no] , [serial-no] is the relative index of the network interface, starting from 1 (the primary network interface is 1) | ["local-ipv4 ","floating-ipv4","mac","network-interface-id","subnet-id","security-group-ids"] |
network/[serial-no] /local-ipv4 | Private IPv4 address of the instance network interface [serial-no] | "10.0.128.6" |
network/[serial-no] /floating-ipv4 | Elastic public IPv4 address of the instance network interface[serial-no] | "11x.xx.xx.xx" |
network/[serial-no] /mac | the mac address of the instance network interface[serial-no] | "02:29:96:8f:xx:xx" |
network/[serial-no] /network-interface-id | ID of the instance network interface[serial-no] | "port-a2uvxxxxxx" |
network/[serial-no] /subnet-id | subnet ID of the instance network interface [serial-no] belongs | "subnet-1vfnyxxxxx" |
network/[serial-no] /security-group-ids | the security group associated to the instance network interface [serial-no] | ["sg-wx0ivnxxxx","sg-jh8ebvxxxx"] |
attributes/customdata/userdata/launch-script | User-defined startup scripts, the result after base64 | "IyEvYmluL2Jhc2gKZWNobyAnaGVsbG8n" |
attributes/customdata/custom-metadata/[key] | User-defined metadata \ corresponding value of [key] |
Metadata access address: http://169.254.169.254/metadata/latest/
, the metadata has a directory level, when it ends with "directory name" + "/", it will return the subordinate metadata items contained in the directory.
Get the metadata root directory inside the system:
curl http://169.254.169.254/metadata/latest/
It will be returned as follows:
["attributes/","network/","placement/","image/","description","instance-name","instance-type","instance-id","pin"]
Specify metadata query according to the directory structure by referring to [Metadata Information] :
Get the hostname of the instance:
curl http://169.254.169.254/metadata/latest/attributes/hostname
Get the ID of the instance:
curl http://169.254.169.254/metadata/latest/instance-id
Invoke-RestMethod http://169.254.169.254/metadata/latest/
attributes/ network/ placement/ image/ description instance-name instance-type instance-id pin
Get the image ID of the instance:
Invoke-RestMethod http://169.254.169.254/metadata/latest/image/image-id
Get the intranet IPv4 address of the instance's primary network interface (the network interface index starts from 1, and the primary network interface fills in "1", and the like):
Invoke-RestMethod http://169.254.169.254/metadata/latest/network/1/local-ipv4
我们的产品专家为您找到最合适的产品/解决⽅案
1v1线上咨询获取售前专业咨询
专业产品顾问,随时随地沟通