Instance Metadata

Last updated: 2020-02-25 10:33:38

PDF

Instance metadata represents the relevant data of the instance and can be used to configure or manage running instances.

Note: Although instance metadata can only be accessed internally from the instance, the data has not been protected through encryption. Anyone who accesses the instance can view its metadata. Therefore, you should take proper precautions to protect sensitive data. For example, using permanent encryption key.

Overview of Instance Metadata

Tencent Cloud provides the following meta-data:

Data DESCRIPTION Version Where It Was Introduced
Instance-id Instance ID 1.0
Instance-name Instance name 1.0
Uuid Instance ID 1.0
Local-ipv4 Instance private IP 1.0
Public-ipv4 Instance public IP 1.0
Mac MAC address of instance's eth0 device 1.0
Placement/region Information of the region in which the instance resides 1.1
Placement/zone Information of the availability zone in which the instance resides 1.1
Network/interfaces/macs/ $ / mac Device address of instance network interface 1.0
Network/network/macs/ Mac / primary-local-ipv4 The primary private IP for the network interface of the instance 1.2
Network/network/macs/ Mac / public-ipv4s The public IP for the network interface of the instance 1.2
Network/interfaces/macs/ $ / vpc-id Example network interface VPC network ID Update of 2017 MULT09MULTHUE 19
Network/interfaces/macs/ $ / subnet-id Instance Network Interface Subnet ID Update of 2017 MULT09MULTHUE 19
Network/network/macs/ Mac / local-ipv4s/ Local-ipv4 / gateway The gateway address for the network interface of the instance 1.2
Network/network/macs/ Mac / local-ipv4s/ Local-ipv4 / local-ipv4 The private IP for the network interface of the instance 1.2
Network/network/macs/ Mac / local-ipv4s/ Local-ipv4 / public-ipv4 The public IP for the network interface of the instance 1.2
Network/network/macs/ Mac / local-ipv4s/ Local-ipv4 / public-ipv4-mode The public network mode for the network interface of the instance 1.2
Network/network/macs/ Mac / local-ipv4s/ Local-ipv4 / subnet-mask The subnet mask for the network interface of the instance 1.2
Payment/charge-type Instance billing mode Update of 2017 MULT09MULTHUE 19
Payment/create-time Instance creation time Update of 2017 MULT09MULTHUE 19
Payment/termination-time Example Terminate time Update of 2017 MULT09MULTHUE 19
App-id AppId of the user to which the instance belongs Update of 2017 MULT09MULTHUE 19
As-group-id Elastic Scaling group ID where the instance resides Update of 2017 MULT09MULTHUE 19
Spot/termination-time Spot instance Terminate time Update of 2017 MULT09MULTHUE 19
/ meta-data/instance/instance-type Instance specifications Update of 2017 MULT09MULTHUE 19
/ instance/image-id Example Image ID Update of 2017 MULT09MULTHUE 19
/ instance/security-group Instance binds security group information Update of 2017 MULT09MULTHUE 19

Fields mac and local-ipv4 in red in the above table indicate the device address and private IP of the network interface specified for the instance, respectively.

The destination URL address of the request is case sensitive. You must construct the destination URL address of a new request according to the returned result of the request.

In the current version, the returned data of placement has been changed. To use the data in the previous version, specify the previous version path or leave the version path empty to access the data of version 1.0. For more information about the returned data of placement, please see Region and Availability Zone .

Querying Instance Metadata

You can access the instance metadata such as instance's local IP and public IP from within an instance to manage connections with external applications.
To view all the instance metadata from within a running instance, use the following URI:

http://metadata.tencentyun.com/latest/meta-data/

To obtain information about the repossession status of a spot instance, you can access the metadata by using the cURL tool or an HTTP GET request.

curl http://metadata.tencentyun.com/latest/meta-data/
  • For resources that do not exist, HTTP error code "404-Not Found" is returned.
  • Operations on instance metadata can only be performed from the Inside the instance Yes, yes. Please log in to the instance first. For more information about logging in to the instance, please refer to the Log in to the Windows instance and Log in to the Linux instance .

Example of querying metadata

The following example shows how to obtain the metadata version information.
Note: When the Tencent Cloud modifies the metadata access path or returned data, a new metadata version is released. If your application or script depends on the structure or returned data of previous version, you can access metadata using the specified previous version.

[qcloud-user]# curl http://metadata.tencentyun.com/
1.0
* February 19, 2019
latest
<meta-data

The following example shows how to view the metadata root Directory. In which / The ending word means Directory, not with / The word at the end represents Access's data. For the specific meaning of Access's data, please refer to the previous article. Instance metadata classification .

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/
instance-id
instance-name
local-ipv4s/
Mac
[NETWORK]
--Placement'{
public-ipv4
uuid

The following example shows how to get the physical location information of an instance. For the relationship between the returned data and the physical location, please refer to Regions and AZs .

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/placement/region
ap-guangzhou

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/placement/zone
"ap-guangzhou-3"

The following example shows how to get the instance Private IP. If there are multiple ENI in the instance, return the network address of eth0 Device.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/local-ipv4
10.104.13.59

The following example shows how to obtain the public IP of an instance.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/public-ipv4
139.199.11.29

The following example shows how to get the instance ID. The instance ID is the unique identity of the instance.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/instance-id
ins-3g445roi

The following example shows how to get the instance uuid. Instance uuid can be used as the unique identity of an instance. It is recommended to use instance ID to distinguish between instances.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/uuid
cfac763a-7094-446b-a8a9-b995e638471a

The following example shows how to obtain the MAC address of an instance's eth0 device.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/mac
52:54:00:BF:B3:51

The following example shows how to get the information of instance ENI. Multiple pieces of ENI will return multiple rows of data, each of which is a piece of ENI's data Directory.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/network/interfaces/macs/
52:54:00:BF:B3:51/

The following example shows how to obtain the information of specified ENI.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/network/interfaces/macs/52:54:00:BF:B3:51/
local-ipv4s/
Mac
VPC ID
Subnet ID
owner-id
primary-local-ipv4
public-ipv4s
local-ipv4s/

The following example shows how to get VPC information to which a specified ENI belongs.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/network/interfaces/macs/52:54:00:BF:B3:51/vpc-id
vpc-ja82n9op

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/network/interfaces/macs/52:54:00:BF:B3:51/subnet-id
subnet-ja82n9op

The following example shows how to get the address list of the specified ENI binding Private IP. If ENI binds multiple Private IP, it returns multiple rows of data.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/network/interfaces/macs/52:54:00:BF:B3:51/local-ipv4s/
10.104.13.59/

The following example shows how to obtain the information of private IP.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/network/interfaces/macs/52:54:00:BF:B3:51/local-ipv4s/10.104.13.59
gateway
local-ipv4s/
public-ipv4
public-ipv4-mode
subnet-mask

The following example shows how to get a Private IP gateway. Only VPC Model can query this data. VPC Model, please refer to Virtual Private Cloud .

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/network/interfaces/macs/52:54:00:BF:B3:51/local-ipv4s/10.104.13.59/gateway
10.15.1.1

The following example shows how to obtain the public network mode of Private IP and Access. Only VPC Model can query this data. Basic network Model through Public gateway Access public network.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/network/interfaces/macs/52:54:00:BF:B3:51/local-ipv4s/10.104.13.59/public-ipv4-mode
NAT

The following example shows how to obtain the public IP bound to a private IP.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/network/interfaces/macs/52:54:00:BF:B3:51/local-ipv4s/10.104.13.59/public-ipv4
139.199.11.29

The following example shows how to obtain the subnet mask of a private IP.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/network/interfaces/macs/52:54:00:BF:B3:51/local-ipv4s/10.104.13.59/subnet-mask
255.255.192.0

The following example shows how to get the instance billing type.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/payment/charge-type
Default: POSTPAID_BY_HOUR.

The following example shows how to get the instance creation time.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/payment/create-time
2018-09-18 11:27:33

The following example shows how to get the time of instance Terminate. (Prepaid mode only)

curl metadata.tencentyun.com/latest/meta-data/spot/termination-time
2018-10-18 11:27:33

The following example shows how spot instance obtains the Terminate time of the instance.

curl metadata.tencentyun.com/latest/meta-data/spot/termination-time
2018-08-18 12:05:33

The following example shows how to get the account AppId to which CVM belongs.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/meta-data/app-id
123456789

Query instance user data

You can specify the instance user data when you create the instance. After setting the cloud-init, CVM can access the data by Access.

Retrieve user data

Users can Access user data in the following ways within CVM.

[qcloud-user]# curl http://metadata.tencentyun.com/latest/user-data
179, client, shanghai