Amazon EC2 offer a range of instance types, and with an EBS backed instance, it’s relatively easy to migrate your server(s) from once instance to another.
The key is a command called ec2-modify-instance-attribute.
I’ve recently wanted to move my instance from something overspec’d and overpowered (m2.xlarge) to something more reasonable.
While it’s nice to have the power sitting there when I need it, it happens rarely enough that I can spare the 5 minutes it takes to spin up an m2.4xl to play around on dynamips.
For my always-on instance, a t1.micro is ideal.
The process for migrating involves the s3cmd library that the lazy among us can install with
sudo apt-get install ec2-api-toolsap.
(I’m running version 1.3-57419 2010-08-31)
The less automated of us can grab the code from http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip
Once set up, there’s a quick set up required involving your EC2 Private key and x.509 cert – (Link)
Add these lines into your .bashrc – (my instance is in eu-west-1 so the EC2_URL saves me adding –region eu-west-1 on each api call. YMMV.)
export EC2_PRIVATE_KEY=/
/pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem
export EC2_CERT=//cert-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem
export EC2_URL=https://ec2.eu-west-1.amazonaws.com
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/
a quick refresh of your .bashrc (source .bashrc) and you should be ready to go.
Here are the steps required to modify your instance type:
- First – let’s check on our running instances
ec2-describe-instances - Grab the instance-id from the output (e.g. i-1a2b3c4d)
- To modify our instance type we first need to shut down the instance.
ec2-stop-instances i-abcdefg - Lets check to see that it’s “stopped”
ec2-describe-instances i-abcdefg - Now lets modify the attributes so that it will start as a t1.micro (or whatever else you want )
ec2-modify-instance-attribute -t t1.micro i-abcdefg - Let’s check to see that the change has applied
ec2-describe-instances i-abcdefg - Start her up again
ec2-start-instances i-abcdefg - You might have to reattach your elastic IP (you do have one, don’t you)
ec2-associate-address 87.238.255.255 -i i-abcdefg - Check to make sure everything is ok
ec2-describe-instances i-abcdefg - And because I’m paranoid, let’s check the console output too
ec2-get-console-output i-abcdefg
Once that’s done, and you can log in again, you’ve successfully changed your instance type (and can reap the performance or cost saving benefits).
There are a few caveats to this (you knew there was a catch coming at somepoint, right?). The main one to watch is that you can only migrate instances of the same platform. e.g. a 64bit running instance (on an m2.4xlarge) cannot move to an m1.small as this is 32-bit only. The t1.micro’s are advertised as “32-bit or 64-bit platform”, so if that’s your aim, you should be good.
Also – this only works on EBS backed instances. If you have an instance backed machine, you’re <redacted> out of luck.
I don’t know of a way to do this via the Web GUI – it would be nice if there was in the future, but for now the API-tools work well.
Setting up the api-tools also leads you into the path of being able to script some actions. Starting/stopping/tweaking things becomes childsplay now.
Happy migrating!
S.
















Recent Comments