Using instance-specific metadata in Eucalyptus

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):

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

or for the custom data:

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):

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:

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

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

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 powered by Disqus