Nov

28

Posted by : Billy | On : November 28, 2011

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

Oct

16

Posted by : Billy | On : October 16, 2011

I’m running Selenium on headless Ubuntu Linux servers (in EC2), using a virtual X-server (Xvfb – X Virtual Frame Buffer). This is of course means that all installs happen via the command line. (You can actually set up a VNC or NX server if you want to login and get a GUI, but that’s really not necessary, eats up resources, and is a fairly slow experience)

This is always very easy when you’re dealing with software you can “apt-get” (such as Firefox), but for other software, it can be a challenge (for example, Google Chrome).

First of all, finding where to download Google Chrome is a bit challenging; unlike a browser where you can just click a link and let the redirects bounce around, when downloading via the command line (using wget) you need the exact URL. Tracking this down isn’t immediately obvious (loading the download page up in a normal browser you see various forms and get some redirects). However, I found it:

https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb

So login to your server via SSH, and:

cd /tmp
sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb

Now to install it:

sudo dpkg -i google-chrome-stable_current_i386.deb

Hmmm.. big oops – unmet dependencies. (At least on my server.) So let’s knock those out:

sudo apt-get -f install

At this point, Chrome should be good to go. Of course, there’s some gotchas with how you’d start Selenium, etc, but that’s for another post …..