Sky and clouds

Create a Working Copy of Your Amazon EC2 Instance for Development or Upgrade

After living with a free Amazon EC2 t1.micro instance for a while, I wanted to upgrade.  The micro instance was great for playing with and learning, but I couldn’t make it work well enough for a real site (it got bogged down due to lack of memory).  So, I purchased a shiny new m1.small instance for three years (the most affordable way to do it).

But then my question was, how do I upgrade a live site?  I found two ways.  The first is to simply stop your current Instance, then select Change Instance Type in the Instances panel.  Wow, that sounded easy, but it seemed a bit too “seat-of-the-pants” for a live site.

The second method, which I will describe here, is much more conservative.  It involves creating a snapshot of your site, creating an image (AMI) from that and launching a new instance from that.  The advantage is that it gives you a chance to test the new instance before going live.  When you’re ready, you can change your Elastic IP to point to the new instance.  This also is a great way to set up a development site, I realized (something I will definitely use).  Here’s how to do it.

First, create a Snapshot of your current site.  Go to Snapshots and hit the Create Snapshot button.  Then choose the Volume you want to copy and give it a name.

Create Snapshot

The next thing you’ll have to do is gather some information required to create an Image.  An Image is created from the Snapshot, but includes some additional information needed for booting and so forth (don’t ask me any more than that – I am no expert on the details).

The first item you’ll need is the Kernel ID.  To get that, go to the Instance that you want to copy, select it, and look at the description below.  Scroll down until you find the Kernel ID, then write it down!  It will look something like this: aki-fc37bacc.  While you’re there, also note your Availability Zone (i.e., “us-west-2a”) and Root Device (i.e., “/dev/sda1”) and Instance Type (i.e., “m1.small”).

The second item you’ll need is the Architecture.  I’m not sure of the best place to find this, but I got it from the original Image that was used to create my Instance.  Go to AMI -> and select the Image (hopefully it is still there).  Scroll down and write down the Architecture.  It will look something like “x86_64” or “i386”.  If your image is no longer there, you can also find the architecture by looking at the AMI ID of your Instance.

Now we’re finally  ready to create the Image.  Go back to your Snapshots page, select your Snapshot, and click the big Create Image button on top.  A big form will pop up.  Enter any name and description you want, but be sure to select the correct Architecture and Kernel ID that you wrote down, very important!  I also increased the Volume Size, because I was upgrading, but you don’t need to do this.  Leave all other values as default and hit “Yes, Create”.

Create image from EBS snapshot

(Note, there is also an option to create an Image directly from your Instance… That might be an easier way to go and is definitely fewer steps.. Let me know if you try it and it works!!)

Now go to AMIs, select the Image you just created and hit the big blue Launch button on top.  You’ll go through five more steps as follows:

  • Choose the Instance Type:  If you’re upgrading, choose the upgraded Instance.  If you’re making a copy, choose the same Instance that you’re using.
  • Configure Instance: Make sure you pick the same zone your original Instance is in.
  • Add Storage:  Leave it at default or increase it.
  • Tag Instance:  Give it a name.
  • Configure Security Group:  Pick Select Existing and choose your desired Security Group.
  • Hit “Review and Launch”!

Go to the Instances page and wait a few minutes while watching the status area.  If you get this error, “Instance reachability check failed”, then your Kernel ID or Architecture could be wrong.

If it was successful, after a few minutes you should be able to enter the Public DNS (on the Instance page) in a browser and see your site!  Of course, all of the links will point back to your original site, so you’ll have to enter the URLs manually if you want to test.

So now you have a copy of your site, either with an upgraded Instance, or with the same Instance which you can use for testing and development!!

If you upgraded to an Instance with more memory, do a “sudo resize2fs /dev/xvda1” to expand your file system to the full disk size (the command might be different for your version of Linux, and your device name could be different).  Do a “df -h” to confirm that your system sees the whole disk.

When you’re happy with it, go to Elastic IPs -> Associate Address and point your IP address at the new Instance!  Remember to Stop your original Instance.  This will stop you from being charged for it.

Hope this helps!  Please respond with any corrections or questions. – Brian

2 thoughts on “Create a Working Copy of Your Amazon EC2 Instance for Development or Upgrade

    1. Hi Dave,

      Thanks for your comment, and sorry for the delay in responding!

      I had hardly any traffic. The problem seemed to be cumulative, i.e., the site would be fine for a few days then start to get slow say a week later. It very well could have been a setting that wasn’t tuned right.

      All I know is at ever since I upgraded to the small instance, I’ve had no problems.


Leave a Comment or Ask a Question

This site uses Akismet to reduce spam. Learn how your comment data is processed.