My last post mentioned that I was trying to move my blog over to Amazon EC2. I have that completed (if you are reading this, it came out of the EC2 cloud), and as promised I am now writing up how to do it.
First, this was not without challenge, of which the primary one is just how to operate EC2. Specifically, here are the challenges I came across and which I will explain (although not all in this single post):
- Creating a key pair,
- Finding a windows server AMI to run,
- Getting an elastic IP,
- Setting up security zones,
- Starting the ami,
- Getting the server password,
- Getting remote access to the server,
- Configuring the server,
- Oh, terminating and rebooting starts over from scratch with the image and therefore blows away all of your config,
- How to bundle your OS into your own AMI, hence saving your configuration, but
- That only saves the C drive, which on an Amazon machine is fairly small,
- How to create your own volumes and attach them to your system,
- Using the volumes to store your application data (hence using it as persistent storage in S3), and
- Restarting your AMI and attaching the volumes
This is a fairly non-trivial list and documentation is pretty sparse on how to do all of this, and hence this blog entry.
When I got started, the best resource I found was Tim Heuer's blog which showed how to get started with EC2. I therefore give him credit here and you can read that post
here.
The first thing to do is get an already existing tool to work with EC2. The one that Tim recommended and that I am using at this point is
ElasticFox, an extension to Firefox. The reason for needing a tool like this is that Amazon does not provide a client for managing EC2. They only provide a web service API, which is actually quite great as you can programmatically do anything with EC2 from outside (or inside) the Amazon cloud. But it does leave you wondering how to get going quickly, and if you are a Firefox user like I am just go and get ElasticFox.
note: ElasticFox is a great tool and you can do most things with it, but it does fall short for automating a sequence of tasks, which I can see will be quite useful. For example, say you want to start one of your AMI's, attach volumes, assign the elastic IP? You need to do these all manually. Hence, I'm working on a WPF application to manage EC2, which will also allow you to do workflow. I'll be posting that to codeplex soon and I'll let you all know when I do this.
One you have ElasticFox installed, open firefox and select Tools -> ElasticFox. Since this is the first time, you will need to enter your Amazon EC2 information. To do this, press the 'Credentials' button:
At which point you will see a form like this (albeit empty if it is your first time):
Enter your account name, access key and secret access key, and press 'Add'. This information will be used by elasticfox to identify you to them and to access your resources.
When that is completed, ElasticFox will present to you similar to the following:
What you see here is a list of AMI's (virtual machines in the amazon library), which is also filtered to just show only those with windows in the title. The naming convention of this is somewhat convoluted, but you will get used to it. Notice that I have one selected, and that is the AMI I'm using to run my blog. It is a windows 2003 R2 instance with IIS and SQL Server 2005 express installed. In the 'Your Instances' list, you can see the virtual systems that you have created and their status. Here you see the one that I am currently running the blog upon.
Now before we can do anything (like starting an instance), you must now create a keypair.
This keypair is used in the web
service call that launches the instances and the private key is used by
ssh to authenticate. The keypair can easily be created in elastic fox, and it will pass it to the service calls for you. The easiest way to create one is to use the 'KeyPairs' tab create a keypair specifying a name
and then save the returned private key in a safe place on your file system.
So, open the keypair tab and you will see something similar to the following, although if this is your first time the list will be empty:
Now press on the green key button, and you will be presented with the following form:
I've entered a name in the field, but name yours anything you want. When you press 'OK', elastic fox passes the name to amazon, and it returns a '.pem' key file to elastic fox, and elasticfox will ask you to save the file somewhere. Please do this, as this keypair / file will be used later (specifically to start an instance)
Fundamentally, you can just right click on any AMI and select 'Launch Instance(s) of this AMI' and you will see a new instance start, go through initialization, and eventually reach the 'Running" state. The running state is when the system is, well, running, and you can RDP in to the box (if your security zone is configured to allow RDP - I'll explain this later).
To get the system into the running state, it will take several minutes of initialization time. I don't know the specifics, but what I can guess from experience is going on is the following:
- Allocation of the AMI to a physical server,
- Sys prepping the AMI so it has a unique system name and IP configurations,
- Changes made to the Amazon firewalls to allow access into the system
- Database entries created to allow manipulation of the virtual system via the web services
To be honest, I skipped a few things here, specifically the security zone configuration and the launch instance dialog. Security zone info I'll cover in another post, and I'll briefly explain the launch instance dialog now. When you select 'Launch Instance(s) of this AMI' you will be presented with this dialog asking you some information that EC2 needs to know to start the instance:

IMHO, at this point, the most important thing to select is the Security Groups to run the instance in. I'll cover them in another post, but in short they are instructions to EC2 on how to open (or keep closed) tunnels through the firewall. The default security group will basically shut down all access, even RDP. But, if you try to connect to the system from ElasticFox, it will see you don't have port 3389 open and will ask you if it is ok if it is ok for it to add 3389 to the defautl zone. So, leaving default here will allow you to RDP to the system (after ElasticFox confirms with you opening 3389), but will block everything else. A good test of this is to try (since this instance by default installs IIS) to connect to the public DNS name of the instance with HTTP. This will be blocked. You can open port 80 later by creating a new security group.
Another thing of importance here is the specification of the keypair. You can see here that I've selected one of my existing keypairs. Again, I'm not sure of the details, but some investigation leads me to believe that firefox passes the .pem file associated to the key back to EC2 when you start the instance. Note that I believe the .pem file is sent is because if you either don't save the file, OR your delete/move the file, you can not start an instance.
There is other information asked here, like the instance type, min and max # of instances, your key pair, availability zone, (I'll comment on these other options in another post) ... but to keep it simple at this point you can at this point just press launch and you will get a machine that is getting spun up (I'll explain all these in other posts):

Here you can see that the VM is pending. Unfortunately Elasticfox does not change this status automatically, and you will need to go and press refresh to get updates, but it will eventually become 'running'.
Once the instance is running, you can right click on it and select 'Connect to Public DNS Name'. Doing this will lauch your RDP client and it will connect to the system, where you will see the familiar Windows 2003 login screen (after pressing ctrl-alt-delete):

At this point you can log in as 'Administrator', but what is the password to the system? During the provisioning, EC2 assigned a secure password to the system. To retrieve this password, right click on the instance and select 'Get Administrator Password'. This will take a few seconds and you will see a message box similar to the following:

Use that password to login. Once in, you can work with the system much like any Win 2003 server. Here I show a picture of My Computer to show you the default drive configurations:

Notice that by default two drives are mounted (C and D) ( the 'other' is the RDP back to my system). The drive is relatively small, and the D quite larger.
Now here's a point I need to mention. I'm not really sure why they mount the D drive. Sure, their documentation says its for storage, but there are a couple of points to mention:
- If you terminate the instance, all changes to both drives are lost. You basically have to restart from the base AMI.
- If the system crashes, it is similar to a termination.
- If you reboot (or shutdown), your changes will stick, but if it ever is terminated or crashes, you lose
- When creating your own bundle/AMI from this system, only the C drive is persisted to the new bundle
So, I don't know what use the D drive is. Sure, temporary storage while the system is running, but you cant install things to it and have them persist, ever. The C drive is somewhat useful as you can save changes to it in your own AMI and restart that AMI with all the changes in tact.
So you might ask then, how to I get data to persist? That is where creating your own volumes (handily stored in S3) and attach those to the system. That will be the topic of a follow up post. The next post will be on using security zones.