Thursday, September 20, 2007

Passing info to EC2 instance on startup.

Amazon EC2 infrastructure provide basic but good methods to pass data to images at startup.

I have created EC2 bundled images that runs a set of scripts on stratup and configures the instance according to data received on launch.

$EC2BIN/ec2-run-instances ami-NNNNNN -d "whenibootupmakemea=webserver" -k My_Key_Pair_Name

What? The command will launch image ami-NNNNNN with my ssh keys My_Key_Pair_Name and will "whenibootupmakemea=webserver" available to the instance. See EC2 docs on how to create the key pairs.

How to get the message?
curl http://169.254.169.254/latest/user-data
Contacts the EC2 control server and request the user-data. This service is provided by amazon.

I use the following command to pass the parameter to my startup scripts.
STARTUP_REQ=`curl --silent http://169.254.169.254/latest/user-data | perl -ne " if (@a=m/whenibootupmakemea=(.*)/) {print @a[0];}"


This is so nice and clean thanks Amazon.

No comments: