Metadata is a service provided to DigitalOcean Droplets that allows a Droplet to access data about itself, i.e. its metadata. Examples of available Droplet metadata include user-provided data (`user-data`), Droplet ID, data center region, IP addresses, and tags. Aside from allowing an easy way for a user to look-up data about a Droplet, metadata can be used to configure a Droplet and its applications.
It can be queried on a Droplet by sending an HTTP GET request to the following link local address:
http://169.254.169.254/metadata/v1/
This document covers how to retrieve metadata from the service, and provides a description for each available endpoint.
An easy way to access the metadata service is to use cURL from a Droplet.
Here is an example of using the curl command to send an HTTP GET request to the top-level of a Droplet's metadata endpoint, /metadata/v1/:
curl http://169.254.169.254/metadata/v1/:
Running this command would output an index of the Droplet's available metadata--this is demonstrated in the Metadata Endpoints section.
There are two types of endpoints in Metadata:
/metadata/v1//metadata/v1/hostnameAn index endpoint will return a directory-like listing of indices and data. A data endpoint will return actual data about the droplet, also known as droplet metadata, e.g. the droplet's ID, hostname, or one of its IP addresses.
The following subsections describe each of the endpoints that are available via the Metadata API.
The entire contents of a Droplet's metadata, in JSON. This endpoint is unique because it returns all of the metadata at once, instead of individual metadata items.
/metadata/v1.json
curl http://169.254.169.254/metadata/v1.json:
{
"droplet_id":2756294,
"hostname":"sample-droplet",
"vendor_data":"#cloud-config\ndisable_root: false\nmanage_etc_hosts: true\n\ncloud_config_modules:\n - ssh\n - set_hostname\n - [ update_etc_hosts, once-per-instance ]\n\ncloud_final_modules:\n - scripts-vendor\n - scripts-per-once\n - scripts-per-boot\n - scripts-per-instance\n - scripts-user\n",
"public_keys":["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCcbi6cygCUmuNlB0KqzBpHXf7CFYb3VE4pDOf/RLJ8OFDjOM+fjF83a24QktSVIpQnHYpJJT2pQMBxD+ZmnhTbKv+OjwHSHwAfkBullAojgZKzz+oN35P4Ea4J78AvMrHw0zp5MknS+WKEDCA2c6iDRCq6/hZ13Mn64f6c372JK99X29lj/B4VQpKCQyG8PUSTFkb5DXTETGbzuiVft+vM6SF+0XZH9J6dQ7b4yD3sOder+M0Q7I7CJD4VpdVD/JFa2ycOS4A4dZhjKXzabLQXdkWHvYGgNPGA5lI73TcLUAueUYqdq3RrDRfaQ5Z0PEw0mDllCzhk5dQpkmmqNi0F [email protected]"],
"region":"nyc3",
"interfaces":{
"private":[
{
"ipv4":{
"ip_address":"10.132.255.113",
"netmask":"255.255.0.0",
"gateway":"10.132.0.1"
},
"mac":"04:01:2a:0f:2a:02",
"type":"private"
}
],
"public":[
{
"ipv4":{
"ip_address":"104.131.20.105",
"netmask":"255.255.192.0",
"gateway":"104.131.0.1"
},
"ipv6":{
"ip_address":"2604:A880:0800:0010:0000:0000:017D:2001",
"cidr":64,
"gateway":"2604:A880:0800:0010:0000:0000:0000:0001"
},
"mac":"04:01:2a:0f:2a:01",
"type":"public"}
]
},
"floating_ip": {
"ipv4": {
"active": false
}
},
"dns":{
"nameservers":[
"2001:4860:4860::8844",
"2001:4860:4860::8888",
"8.8.8.8"
]
}
}
The top-level metadata index. This index can be navigated to find all available Metadata endpoints.
/metadata/v1/
curl http://169.254.169.254/metadata/v1/
id
hostname
user-data
vendor-data
public-keys
region
interfaces/
dns/
floating_ip/
The Droplet's unique identifier. This is automatically generated upon Droplet creation.
/metadata/v1/id
curl http://169.254.169.254/metadata/v1/id
2756294
The Droplet's hostname, as specified by the user during Droplet creation.
/metadata/v1/hostname
curl http://169.254.169.254/metadata/v1/hostname
sample-droplet
The user data that was provided by the user during Droplet creation. User data can contain arbitrary data for miscellaneous use or, with certain Linux distributions, an arbitrary shell script or cloud-config file that will be consumed by a variation of cloud-init upon boot. At this time, cloud-config support is included with CoreOS, Ubuntu 14.04, and CentOS 7 images on DigitalOcean.
/metadata/v1/user-data
curl http://169.254.169.254/metadata/v1/user-data
#! /bin/bash
echo "Data from user"
Vendor-provided data that can be used to configure Droplets upon their creation. This is similar to user data, but it is provided by DigitalOcean instead of the user.
/metadata/v1/vendor-data
curl http://169.254.169.254/metadata/v1/vendor-data
#cloud-config
disable_root: false
manage_etc_hosts: true
cloud_config_modules:
- ssh
- set_hostname
- [ update_etc_hosts, once-per-instance ]
cloud_final_modules:
- scripts-vendor
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
- scripts-user
Public SSH key(s) that were added to the Droplet's root user's authorized_keys file during Droplet creation.
/metadata/v1/public-keys
curl http://169.254.169.254/metadata/v1/public-keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCcbi6cygCUmuNlB0KqzBpHXf7CFYb3VE4pDOf/RLJ8OFDjOM+fjF83a24QktSVIpQnHYpJJT2pQMBxD+ZmnhTbKv+OjwHSHwAfkBullAojgZKzz+oN35P4Ea4J78AvMrHw0zp5MknS+WKEDCA2c6iDRCq6/hZ13Mn64f6c372JK99X29lj/B4VQpKCQyG8PUSTFkb5DXTETGbzuiVft+vM6SF+0XZH9J6dQ7b4yD3sOder+M0Q7I7CJD4VpdVD/JFa2ycOS4A4dZhjKXzabLQXdkWHvYGgNPGA5lI73TcLUAueUYqdq3RrDRfaQ5Z0PEw0mDllCzhk5dQpkmmqNi0F [email protected]
The region code of where the Droplet resides.
/metadata/v1/region
curl http://169.254.169.254/metadata/v1/region
nyc3
An index of all network interfaces by type, e.g. "public" and "private".
/metadata/v1/interfaces/
curl http://169.254.169.254/metadata/v1/interfaces/
public/
private/
An enumerated index of all network interfaces that are of the specified interface type.
/metadata/v1/interfaces/public/
curl http://169.254.169.254/metadata/v1/interfaces/public/
0/
An index of the attributes of the specified network interface.
/metadata/v1/interfaces/public/0/
curl http://169.254.169.254/metadata/v1/interfaces/public/0/
mac
type
ipv4/
ipv6/
The MAC address of the specified network interface.
/metadata/v1/interfaces/public/0/mac
curl http://169.254.169.254/metadata/v1/interfaces/public/0/mac
04:01:2a:0f:2a:03
The type of the specified network interface.
/metadata/v1/interfaces/public/0/type
curl http://169.254.169.254/metadata/v1/interfaces/public/0/type
public
An index of the specified network interface's IPv4 attributes.
/metadata/v1/interfaces/public/0/ipv4/
curl http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/
address
netmask
gateway
The IPv4 address of the specified network interface.
/metadata/v1/interfaces/public/0/ipv4/address
curl http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address
104.131.20.105
The netmask of the specified network interface.
/metadata/v1/interfaces/public/0/ipv4/netmask
curl http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/netmask
255.255.192.0
The gateway of the specified network interface.
/metadata/v1/interfaces/public/0/ipv4/gateway
curl http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/gateway
104.131.0.1
An index of the specified network interface's IPv6 attributes.
/metadata/v1/interfaces/public/0/ipv6/
curl http://169.254.169.254/metadata/v1/interfaces/public/0/ipv6/
address
cidr
gateway
The IPv6 address of the specified network interface.
/metadata/v1/interfaces/public/0/ipv6/address
curl http://169.254.169.254/metadata/v1/interfaces/public/0/ipv6/address
2604:A880:0800:0010:0000:0000:017D:2001
The IPv6 CIDR block size of the specified network interface.
/metadata/v1/interfaces/public/0/ipv6/cidr
curl http://169.254.169.254/metadata/v1/interfaces/public/0/ipv6/cidr
64
The IPv6 gateway of the specified network interface.
/metadata/v1/interfaces/public/0/ipv6/gateway
curl http://169.254.169.254/metadata/v1/interfaces/public/0/ipv6/gateway
2604:A880:0800:0010:0000:0000:0000:0001
An index of the specified "Anchor" network interface's IPv4 attributes.
Note: An "Anchor" interface is an implementation detail of DigitalOcean Floating IPs.
/metadata/v1/interfaces/public/0/anchor_ipv4/
curl http://169.254.169.254/metadata/v1/interfaces/public/0/anchor_ipv4/
address
netmask
gateway
The IPv4 address of the specified "Anchor" network interface.
Note: An "Anchor" interface is an implementation detail of DigitalOcean Floating IPs.
/metadata/v1/interfaces/public/0/anchor_ipv4/address
curl http://169.254.169.254/metadata/v1/interfaces/public/0/anchor_ipv4/address
10.17.0.160
The netmask of the specified "Anchor" network interface.
Note: An "Anchor" interface is an implementation detail of DigitalOcean Floating IPs.
/metadata/v1/interfaces/public/0/anchor_ipv4/netmask
curl http://169.254.169.254/metadata/v1/interfaces/public/0/anchor_ipv4/netmask
255.255.0.0
The gateway of the specified "Anchor" network interface.
Note: An "Anchor" interface is an implementation detail of DigitalOcean Floating IPs.
/metadata/v1/interfaces/public/0/anchor_ipv4/gateway
curl http://169.254.169.254/metadata/v1/interfaces/public/0/anchor_ipv4/gateway
10.17.0.1
An index of Floating IP attributes.
/metadata/v1/floating_ip/
curl http://169.254.169.254/metadata/v1/floating_ip/
ipv4/
An index of IPv4 Floating IP attributes.
/metadata/v1/floating_ip/ipv4/
curl http://169.254.169.254/metadata/v1/floating_ip/ipv4/
active
ip_address
Displays true if a Floating IP is currently assigned to the Droplet and false if it is not.
/metadata/v1/floating_ip/ipv4/active
curl http://169.254.169.254/metadata/v1/floating_ip/ipv4/active
true
The IP address of the Floating IP that is currently assigned to the Droplet.
/metadata/v1/floating_ip/ipv4/ip_address
curl http://169.254.169.254/metadata/v1/floating_ip/ipv4/ip_address
45.55.96.17
An index of DNS attributes.
/metadata/v1/dns/
curl http://169.254.169.254/metadata/v1/dns/
nameservers
The nameserver entries that are added to a Droplet's /etc/resolv.conf file during creation.
/metadata/v1/dns/nameservers
curl http://169.254.169.254/metadata/v1/dns/nameservers
2001:4860:4860::8844
2001:4860:4860::8888
8.8.8.8
An index of tags associated with the droplet.
/metadata/v1/tags/
curl http://169.254.169.254/metadata/v1/tags/
production
application
v1
Metadata uses standard HTTP response codes when responding to all requests. As such, a succesful request returns a 200 (OK) response.
You may use the -w "\n\n%{http_code}\n" cURL option to append the HTTP response code to the end of the metadata response, like so:
curl -w "\n\n%{http_code}\n" http://169.254.169.254/metadata/v1/
If you access an index endpoint but forget to add the trailing slash, you will receive a 301 Moved Permanently response with this content:
Moved Permanently.
If you access an endpoint that does not exist, you will receive a 404 Not Found response with this content:
not found
Resolve this by using an existing endpoint.