A current project I am working on has a requirement that custom machine images be built and maintained such that they are usable both from within Amazon EC2 and on virtual machines hosted outside of EC2. These images are all based on the Windows operating system. Since we want to build each machine image only once (we will have about 200 of them!) it left us with a couple of options:
- Build the custom image on EC2 and export it for use on outside virtual machines
- Build the custom image on an outside virtual machine and import it for use in EC2
This article explores the second option. I will outline some of the challenges I experienced along the way and how I resolved them. Hopefully this may help someone else who is trying to do the same sort of thing.
In theory, the process is simple. Amazon has provided command line tools and decent documentation on how to do this. As with many endeavors, however, the devil is often in the details.
I had wanted to start from VMware images. VWware virtual disk files use the vmdk format. I soon discovered, however, that not all vmdk files are created equal. That is vmdk files which are used for vSphere are not the same as the vmdk files used in VMware Workstation. The EC2 command line tools will complain if you try to use a workstation vmdk. Unfortunately I did not have vSphere available at my disposal.
So, I decided instead to start from a vhd format disk. I know that there are products which claim to convert one to another but I did not want to go there at this point. I used Microsoft Virtual PC 2007 to create a base Windows Server 2008 virtual machine from an ISO image I downloaded using my MSDN subscription. At least that was a relatively easy way to get started. I then went on to customize that image for my requirements.
Next just use the tools and upload the image, right?
Well, for me it took a few tries. I learned after the first that running ec2-upload-disk-image from my local machine takes over 24 hours to complete. My vhd file was about 5.5 GiB. Not huge, but pretty big. I guess I have slow upload speed. After the upload completes some processing takes place on Amazon’s servers. This requires additional time. You monitor progress using ec2-describe-conversion-tasks. My first attempt seemed to get stuck. It never advanced beyond 6% complete.
For subsequent attempts I zipped the vhd file, uploaded it to S3 and then downloaded it to an EC2 instance I had provisioned with the command line tools. There I could un-zip the file and run ec2-upload-disk-image. That whole process, end to end, took about 5 hours so at least that was some improvement. My second effort spun up and I thought I was good to go.
Not so fast! It seemed now that even though the machine was running I had no way to connect to it. I had read in the documentation that Remote Desktop had to be enabled and that port 3389 needed to be opened on the Windows firewall. I had done all that. Still, no go.
For my next attempt I decided to have IIS started on the image so I could at least know that it was alive and communicating on the network. I also double-checked the remote connection settings, made sure that there were no conflicts on port 3389 and that it was definitely open on the Windows firewall.
This time I could see the web server but still couldn’t connect via RDP! To me that meant it had to be a firewall issue. After verifying that the EC2 security group had 3389 open I decided I would try again but this time I would turn the Windows firewall completely off. That worked! I was able to connect to my custom created instance using RDP.
Is there a better way to do this? Probably. However, at least now I know there is a way to achieve the goal! Of course I am not done yet. Make it work, make it right, make it fast!
For more about cloud computing with Amazon Web Services Learning Tree is developing a new course dedicated to that very topic!