Amazon EC2 Instances have metadata they can access. They get it by accessing a web server on a link-local address, 169.254.169.254. This article shows how to get the metadata and example responses for the types of metadata available.


Startup

First we will start up an instance. In this case, we are starting a t1.micro in the us-east-1 region using the image ami-c7aa60ae in the group default and using the key key-name.

Console - user@hostname ~ $

1
2
3
4
5
6
ec2-run-instances \
--region us-east-1 \
ami-c7aa60ae \
--group default \
--key key-name \
--instance-type t1.micro

Output

1
2
RESERVATION     r-e98f4f88      902460189751    default
INSTANCE        i-05948966      ami-c7aa60ae                    pending key-name        0               t1.micro        2011-12-09T10:43:22+0000        us-east-1a     aki-805ea7e9                     monitoring-disabled                            ebs                                      paravirtual     xen             sg-03987d6a     default

Describe the instance to get the public hostname:

Console - user@hostname ~ $

1
2
3
ec2-describe-instances \
--region us-east-1 \
i-05948966

Output

1
2
3
RESERVATION     r-e98f4f88      902460189751    default
INSTANCE        i-05948966      ami-c7aa60ae    ec2-184-73-56-99.compute-1.amazonaws.com        domU-12-31-39-02-14-35.compute-1.internal       running key-name        0               t1.micro        2011-12-09T10:43:22+0000   us-east-1a      aki-805ea7e9                    monitoring-disabled     184.73.56.99    10.248.27.195                   ebs                                     paravirtual     xen             sg-03987d6a        default
BLOCKDEVICE     /dev/sda1       vol-79a02f14    2011-12-09T10:48:24.000Z

SSH to the instance:

Console - user@hostname ~ $

1
ssh -i ~/.ssh/key-name.pem ec2-user@ec2-184-73-56-99.compute-1.amazonaws.com

Query

Example

Now we will use curl to access the metadata pages. We will go through and show the various pieces of metadata available to us.

Console - ec2-user@domU-12-31-39-02-14-35 ~ $

1
curl http://169.254.169.254/

Output

1
2
3
4
5
6
7
8
9
10
11
12
1.0
2007-01-19
2007-03-01
2007-08-29
2007-10-10
2007-12-15
2008-02-01
2008-09-01
2009-04-04
2011-01-01
2011-05-01
latest

Metadata

http://169.254.169.254/

http://169.254.169.254/

1
2
3
4
5
6
7
8
9
10
11
12
1.0
2007-01-19
2007-03-01
2007-08-29
2007-10-10
2007-12-15
2008-02-01
2008-09-01
2009-04-04
2011-01-01
2011-05-01
latest

http://169.254.169.254/latest/

http://169.254.169.254/latest/

1
2
3
dynamic
meta-data
user-data

http://169.254.169.254/latest/meta-data/

http://169.254.169.254/latest/meta-data/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
hostname
instance-action
instance-id
instance-type
kernel-id
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-hostname
public-ipv4
public-keys/
reservation-id
security-groups

http://169.254.169.254/latest/meta-data/ami-id

http://169.254.169.254/latest/meta-data/ami-id

1
ami-c7aa60ae

http://169.254.169.254/latest/meta-data/ami-launch-index

http://169.254.169.254/latest/meta-data/ami-launch-index

1
0

http://169.254.169.254/latest/meta-data/ami-manifest-path

http://169.254.169.254/latest/meta-data/ami-manifest-path

1
(unknown)

http://169.254.169.254/latest/meta-data/block-device-mapping/

http://169.254.169.254/latest/meta-data/block-device-mapping/

1
2
3
ami
ephemeral0
root

http://169.254.169.254/latest/meta-data/block-device-mapping/ami

http://169.254.169.254/latest/meta-data/block-device-mapping/ami

1
/dev/sda1

http://169.254.169.254/latest/meta-data/block-device-mapping/ephemeral0

http://169.254.169.254/latest/meta-data/block-device-mapping/ephemeral0

1
/dev/sda2

http://169.254.169.254/latest/meta-data/block-device-mapping/root

http://169.254.169.254/latest/meta-data/block-device-mapping/root

1
/dev/sda1

http://169.254.169.254/latest/meta-data/hostname

http://169.254.169.254/latest/meta-data/hostname

1
domU-12-31-39-02-14-35.compute-1.internal

http://169.254.169.254/latest/meta-data/instance-action

http://169.254.169.254/latest/meta-data/instance-action

1
none

http://169.254.169.254/latest/meta-data/instance-id

http://169.254.169.254/latest/meta-data/instance-id

1
i-05948966

http://169.254.169.254/latest/meta-data/instance-type

http://169.254.169.254/latest/meta-data/instance-type

1
t1.micro

http://169.254.169.254/latest/meta-data/kernel-id

http://169.254.169.254/latest/meta-data/kernel-id

1
aki-805ea7e9

http://169.254.169.254/latest/meta-data/local-hostname

http://169.254.169.254/latest/meta-data/local-hostname

1
domU-12-31-39-02-14-35.compute-1.internal

http://169.254.169.254/latest/meta-data/local-ipv4

http://169.254.169.254/latest/meta-data/local-ipv4

1
10.248.27.195

http://169.254.169.254/latest/meta-data/mac

http://169.254.169.254/latest/meta-data/mac

1
12:31:39:02:14:35

http://169.254.169.254/latest/meta-data/metrics/

http://169.254.169.254/latest/meta-data/metrics/

1
vhostmd

http://169.254.169.254/latest/meta-data/metrics/vhostmd

http://169.254.169.254/latest/meta-data/metrics/vhostmd

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?xml version="1.0" encoding="UTF-8"?>
  <metrics>
    <metric context='host' type='string' unit=''>
      <name>Solution</name>
      <value>Amazon</value>
    </metric>
    <metric context='host' type='string' unit=''>
      <name>Technology (Type)</name>
      <value>EC2</value>
    </metric>
    <metric context='host' type='string' unit=''>
      <name>Solution Version</name>
      <value>51742768</value>
    </metric>
    <metric context='host' type='string' unit=''>
      <name>Virtual Machine Name</name>
      <value>ami-c7aa60ae</value>
    </metric>
    <metric context='host' type='string' unit=''>
      <name>Virtual Machine Host Name</name>
      <value>ip-10-248-27-195</value>
    </metric>
    <metric context='host' type='string' unit=''>
      <name>Virtual Machine ID</name>
      <value>i-05948966</value>
    </metric>
    <metric context='host' type='string' unit=''>
      <name>Hypervisor Host Name</name>
      <value>02ca48ae08ba39d9</value>
    </metric>
    <metric context='host' type='uint64' unit='MHz'>
      <name>Maximum Processor Frequency</name>
      <value>2600</value>
    </metric>
    <metric context='host' type='string' unit=''>
      <name>Processor Type</name>
      <value>Dual-Core AMD Opteron(tm) Processor 2218 HE</value>
    </metric>
    <metric context='host' type='uint64' unit='CPU'>
      <name>Number of Physical CPUs</name>
      <value>1</value>
    </metric>
    <metric context='host' type='uint64' unit='ms'>
      <name>Total CPU Time</name>
      <value>6300000</value>
    </metric>
    <metric context='host' type='uint64' unit='ms'>
      <name>Elapsed Time</name>
      <value>620321705</value>
    </metric>
    <metric context='host' type='real64' unit='CPU'>
      <name>Physical CPUs Consumed</name>
      <value>0.01</value>
    </metric>
    <metric context='vm' type='uint64' unit='CPU'>
      <name>Virtual Processors</name>
      <value>1</value>
    </metric>
    <metric context='vm' type='uint64' unit='MHz'>
      <name>Actual Processor Frequency</name>
      <value>2600</value>
    </metric>
    <metric context='vm' type='uint64' unit='ms'>
      <name>Total CPU Time Consumed</name>
      <value>6300000</value>
    </metric>
    <metric context='vm' type='uint64' unit='CPU'>
      <name>Capacity Consumed</name>
      <value>1</value>
    </metric>
    <metric context='vm' type='uint64' unit='MHz'>
      <name>Guaranteed Capacity</name>
      <value>2600</value>
    </metric>
    <metric context='vm' type='uint64' unit='%'>
      <name>Guaranteed Capacity Consumed</name>
      <value>100</value>
    </metric>
    <metric context='vm' type='uint64' unit='CPU'>
      <name>Additional Capacity Available</name>
      <value>0</value>
    </metric>
    <metric context='vm' type='uint64' unit='CPU'>
      <name>Available Capacity</name>
      <value>1</value>
    </metric>
    <metric context='vm' type='uint64' unit='%'>
      <name>Available Capacity Consumed</name>
      <value>100</value>
    </metric>
    <metric context='vm' type='uint64' unit='MHz'>
      <name>Capacity Limit</name>
      <value>2600</value>
    </metric>
    <metric context='vm' type='uint64' unit='%'>
      <name>Weight</name>
      <value>100</value>
    </metric>
    <metric context='host' type='uint64' unit='MB'>
      <name>Physical Memory</name>
      <value>615</value>
    </metric>
    <metric context='host' type='uint64' unit='%'>
      <name>Physical Memory Consumed</name>
      <value>100</value>
    </metric>
    <metric context='host' type='uint64' unit='MB'>
      <name>Memory Paged Out</name>
      <value>0</value>
    </metric>
    <metric context='host' type='uint64' unit='MB'>
      <name>Memory Shared</name>
      <value>0</value>
    </metric>
    <metric context='vm' type='uint64' unit='MB'>
      <name>Memory Configured</name>
      <value>615</value>
    </metric>
    <metric context='vm' type='uint64' unit='MB'>
      <name>Memory Consumed</name>
      <value>615</value>
    </metric>
    <metric context='vm' type='uint64' unit='MB'>
      <name>Additional Memory Available</name>
      <value>0</value>
    </metric>
    <metric context='vm' type='uint64' unit='%'>
      <name>Available Memory Consumed</name>
      <value>100</value>
    </metric>
    <metric context='vm' type='uint64' unit='MB'>
      <name>Guaranteed Memory</name>
      <value>615</value>
    </metric>
    <metric context='vm' type='uint64' unit='%'>
      <name>Guaranteed Memory Consumed</name>
      <value>100</value>
    </metric>
    <metric context='vm' type='uint64' unit='MB'>
      <name>Memory Swapped Out</name>
      <value>0</value>
    </metric>
    <metric context='vm' type='uint64' unit='%'>
      <name>Weight</name>
      <value>100</value>
    </metric>
    <metric context='vm' type='uint64' unit='MB'>
      <name>Memory Limit</name>
      <value>615</value>
    </metric>
  </metrics>

http://169.254.169.254/latest/meta-data/network/

http://169.254.169.254/latest/meta-data/network/

1
interfaces/

http://169.254.169.254/latest/meta-data/network/interfaces/

http://169.254.169.254/latest/meta-data/network/interfaces/

1
macs/

http://169.254.169.254/latest/meta-data/network/interfaces/macs/

http://169.254.169.254/latest/meta-data/network/interfaces/macs/

1
12:31:39:02:14:35/

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/

1
2
3
4
5
6
7
device-number
local-hostname
local-ipv4s
mac
owner-id
public-hostname
public-ipv4s

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/device-number

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/device-number

1
0

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/local-hostname

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/local-hostname

1
domU-12-31-39-02-14-35.compute-1.internal

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/local-ipv4s

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/local-ipv4s

1
10.248.27.195

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/mac

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/mac

1
12:31:39:02:14:35

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/public-hostname

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/public-hostname

1
ec2-184-73-56-99.compute-1.amazonaws.com

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/public-ipv4s

http://169.254.169.254/latest/meta-data/network/interfaces/macs/12:31:39:02:14:35/public-ipv4s

1
184.73.56.99

http://169.254.169.254/latest/meta-data/placement/

http://169.254.169.254/latest/meta-data/placement/

1
availability-zone

http://169.254.169.254/latest/meta-data/placement/availability-zone

http://169.254.169.254/latest/meta-data/placement/availability-zone

1
us-east-1a

http://169.254.169.254/latest/meta-data/profile

http://169.254.169.254/latest/meta-data/profile

1
default-paravirtual

http://169.254.169.254/latest/meta-data/public-hostname

http://169.254.169.254/latest/meta-data/public-hostname

1
ec2-184-73-56-99.compute-1.amazonaws.com

http://169.254.169.254/latest/meta-data/public-ipv4

http://169.254.169.254/latest/meta-data/public-ipv4

1
184.73.56.99

http://169.254.169.254/latest/meta-data/public-keys/

http://169.254.169.254/latest/meta-data/public-keys/

1
0=key-name

http://169.254.169.254/latest/meta-data/public-keys/0/

http://169.254.169.254/latest/meta-data/public-keys/0/

1
openssh-key

http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key

http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key

1
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC1M1Cc7AljcVWPfErLUq4fi2L4W0O0hLdlhXDJABv9gtTnZ9c7QrQBUaAvOdns+a6R8dqjYEQrRd98pfpoHu4hDFa3KIX78VDl1p5wzAJOxvLpdjWYPAs3+fYbiuUdFFKLW8DXfZqLD21P0BI4c9qLd0OM7lbt7JvCrUh0NTE8T/Fwz34V8pWPNndEikT6+BsgZrxAaJfbSsKQFNG4Xz1//gcRi0YHFe0vnb0euNFGXpd/12AqqB5dj4W6z9Zqo5Hl1+sZ44qRW1KI/gMUOA7FeAKOz9dhmaZtDH27S6YWx0Ep5KzM/dTHRRKUATbhuPXhfBA6sy15aIpYf9fpNj0d key-name

http://169.254.169.254/latest/meta-data/reservation-id

http://169.254.169.254/latest/meta-data/reservation-id

1
r-e98f4f88

http://169.254.169.254/latest/meta-data/security-groups

http://169.254.169.254/latest/meta-data/security-groups

1
default

Shutdown

Shutdown the instance:

Console - ec2-user@domU-12-31-39-02-14-35 ~ $

1
sudo shutdown -h now

Then terminate the instance:

Console - user@hostname ~ $

1
2
3
ec2-terminate-instances \
--region us-east-1 \
i-05948966

Output

1
INSTANCE        i-05948966      stopped terminated

Comments