Every EC2 instance is based on an Amazon Machine Image (AMI), which is basically a VM image. These can be “off the shelf”, or even better, you can customize one to your exact needs.This is really useful when you want to replicate machines, spreading work load across a mini cluster.
You can automate this from ColdFusion. Typically I’ll have a URL I call that starts up a series of tasks on each machine. Since the address for each machine is assigned by Amazon (you can get fancy with Elastic IPs if you’d like, but there’s really no need), it’s a matter of querying Amazon for the list of server names. Of course, if you’re running different types of machines, you want to filter by AMI ID, which of course changes each time you build a new image.
I won’t get into the exact code for querying here, but here’s how you get the AMI for a given machine from within ColdFusion: (Assumption is that this machine is one of your cluster machines, so once you have its AMI ID, you can filter for other machines like it)
<cfscript>
if (! isdefined("application.amiId")){
application.amiId=fileRead("http://169.254.169.254/2011-01-01/meta-data/ami-id");
}
request.amiID = application.amiId;
</cfscript>
Note: above tested in Open BlueDragon 2.0 – use <cfhttp> tag for engines that don’t support fileRead(uri)
As you might guess, that IP address is an API for EC2 metadata. The date is the API version (call the root IP address to get a list of API versions), “meta-data” is the API service, and “ami-id” is the value you’re requesting. (Call the URL without “ami-id” for a list of available values). For more information, go to http://docs.amazonwebservices.com/AWSEC2/2008-08-08/DeveloperGuide/index.html?AESDG-chapter-instancedata.html


