MDLog:/sysadmin

The Journal Of A Linux Sysadmin

Using Instance-specific Metadata in Eucalyptus

| Comments

One of the great features of Amazon EC2 is the possibility to dynamically query and use instance specific metadata, or even custom data. This can be useful for various reasons, and the greatest advantage I’ve personally seen into this, is the possibility to allow the instance to have some information on how to configure itself when first booting (using chef or puppet, or some other configuration management tool).

The Amazon documentation explains how to get this information, basically just by using simple http get requests on the ip: 169.254.169.254, like for ex (for the metadata index):

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

or for the custom data:

1
curl http://169.254.169.254/latest/user-data

Eucalyptus supports this great feature (starting with v1.4), but we obviously need to target a different ip to retrieve this information (as the amazon ip has nothing to do with our internal cloud ;) ). We need to use the cloud controller IP for the request and the port it is bound (by default 8773 if you have not changed it). This will look like this (you need to run it from inside the actual instance):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
curl http://<CC_IP>:8773/latest/meta-data
block-device-mapping/
security-groups
ami-manifest-path
ancestor-ami-ids
public-keys/
reservation-id
ramdisk-id
public-keys/0/
ami-launch-index
kernel-id
instance-type
local-hostname
local-ipv4
hostname
product-codes
public-ipv4
instance-id
public-hostname
ami-id
placement/

For the user data we can start the eucalyptus instance with:

1
ec2-run-instances <EMI> -d "myhostname" ...other params...

and later we can then retrieve that information from inside the instance using:

1
2
curl http://<CC_IP>:8773/latest/user-data
myhostname

While the documentation for Eucalyptus is getting better with every new version there are still missing parts like this one, and hopefully people looking for this information will find this article useful.

Comments