Get Instance Metadata

Instance Metadata Overview

Instance metadata provides information about a running instance, such as network configuration, instance identifiers, and other runtime attributes. The metadata service is accessible from within the instance through a link-local IP address.

The metadata entries are organized in a hierarchical structure similar to a directory tree. Each path represents either a metadata item or a subdirectory containing additional metadata entries.

When a metadata directory is requested, the service returns the list of all subdirectories or metadata items available under that path.

1. Common Use Cases

Instance metadata is commonly used by automation tools, initialization scripts, and cloud-native applications to retrieve instance-specific configuration at runtime.

Typical use cases include:

  • Initialization scripts – Retrieve instance information such as instance ID, region, or IP during startup.

    INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
  • Network configuration discovery – Identify network interfaces, IP addresses, or subnet information on instances with multiple network interfaces.

  • Temporary credentials retrieval – Obtain temporary API credentials provided by the metadata service instead of storing long-term access keys.

  • Cloud initialization – Initialization tools (such as cloud-init) can retrieve user-data and meta-data to configure the instance during boot.

2. Metadata Service Endpoint

The instance metadata service is available from within the instance at the following base URL:

Applications or scripts running inside the instance can query specific metadata entries by sending HTTP requests to this endpoint.

3. Example: Query Network Interface Metadata

The following example retrieves the list of MAC address directories for all network interfaces attached to the instance:

Example response:

Next, you can continue to access information about a specific MAC, for example:

You can get the IP of this network interface.

Metadata Details

Instance metadata is organized in a hierarchical structure similar to a directory tree and can be accessed level by level. When a metadata directory is queried, the service returns the list of subdirectories or metadata entries under that path.

For example, querying the network/interfaces/macs/ directory returns the MAC address directories for all network interfaces attached to the instance.

Basic Network Configuration

Metadata
Description
Example

network/interfaces/macs/

AC addresses of all network interfaces on the instance.

52:54:00:8d:XX:XX/ 52:54:00:3a:XX:XX/

/network/interfaces/macs/{mac addr}/

Metadata directories for the specified network interface ({mac addr}), where {mac addr} is the MAC address of the interface.

ipv6-gateway network-interface-id primary-ip-address public-ipv4 public-ipv4s primary-ipv6-address ipv6-prefix gateway subnet-cidr-block subnet-ipv6-cidr-block

network/interfaces/macs/{mac addr}/network-interface-id

ID of the specified network interface on the instance.

161709631348749****

network/interfaces/macs/{mac addr}/primary-ip-address

Primary private IPv4 address of the specified network interface.

10.0.0.7

network/interfaces/macs/{mac addr}/primary-ipv6-address

Primary IPv6 address of the specified network interface.

XXXX:XXXX:0:d6c8:0:1::2

network/interfaces/macs/{mac addr}/private-ipv4s

Secondary private IPv4 addresses of the specified network interface (excluding the primary private IPv4 address).

["10.0.0.10"]

network/interfaces/macs/{mac addr}/public-ipv4

Default outbound public IPv4 address of the specified network interface.

XX.XX.206.251

network/interfaces/macs/{mac addr}/public-ipv4s

List of public IPv4 addresses associated with the specified network interface.

["XX.XX.206.251","XX.XX.214.234"]

network/interfaces/macs/{mac addr}/ipv6-prefix

IPv6 CIDR of the specified network interface.

XXXX:XXXX:0:d6c8:0:1::/96

network/interfaces/macs/{mac addr}/gateway

IPv4 gateway address of the specified network interface.

10.0.0.1

network/interfaces/macs/{mac addr}/ipv6-gateway

IPv6 gateway address of the specified network interface.

fe80::1

network/interfaces/macs/{mac addr}/subnet-cidr-block

List of IPv4 CIDRs of the subnet to which the specified network interface belongs.

10.0.0.0/24

network/interfaces/macs/{mac addr}/subnet-ipv6-cidr-block

List of IPv6 CIDRs of the subnet to which the specified network interface belongs.

XXXX:XXXX:0:d6c8::/64

network/interfaces/macs/{mac addr}/subnet-id

Subnet ID of the subnet to which the specified network interface belongs.

161709631348749****

Last updated