CloudStacking.com | Stacking solutions in the cloud for fun and profit

Adding Resources (Resizing) an AWS EC2 Instance

There are a couple of ways of adding resources in the Cloud

Cloud Computing, when exercised in all of it’s glory is about Services rather than Servers - this often facilitated by some form of task scheduling such as Message Queuing (click here to read my introduction to Amazon SQS and how to best leverage it for Cloud Computing).

In this paradigm, adding resources to the Service (again, Servers are irrelevant) is dome simply by adding more servers to our Service’s pool, rather than adding resources to any server in particular.

But not every deployment is a textbook example of Cloud Computing - and that’s fine. Sometimes we have to deal with a component that simply can’t be distributed between servers (often the case with database servers), and sometimes we are running workloads so light that it really makes more sense to throw more resources at our single server rather than face the complexities of re-architecting our application to scale between multiple servers.

Not all Instances were created (launched) equal

At it’s essence an Instance is an Amazon Machine Image (AMI) that has been deployed to a (virtual) machine and powered-up - hence the term Instance. It is a (running) Instance of an (Amazon Machine) Image. Going back to the machine part of the equation, AWS offers different Instance types (read: sizes), each with a predefined amount of CPU, RAM and I/O (priority) resources. Note that Instance types are either 32 or 64 bit - we’ll get back to this important detail in just a bit.

When we provision a new Instance, we either explicitly specify a type (read: size), or just default to small, which comes with 1.7 GB of memory and 1 EC2 Compute Unit.

Cutting to the chase: Changing the Instance type (size)

AWS gives us the option of changing the type of an already provisioned Instance by invoking the API call ModifyInstanceAttribute to change the instanceType value to either a larger or smaller, according to our discretion.

There are three limitations that we need to keep in mind:

  1. This action can only performed on Instances that are in the stopped state.
  2. Derived from the previous: the Instance must be EBS-backed (since Instance Store Instances can’t stop - only terminate).
  3. It is not permitted to switch between 32 and 64 bit Instance types due to AMI limitations. For example: Small Instances can only grow to Medium while Extra Large Instances can only shrink to Large.

This action can also be performed from the command-line via the EC2 API Tools (getting started with the tools isn’t as easy as I hope it would be. but here is an excellent guide to get us started).

Once the API tools are set-up, the syntax is very straightforward. The following is a working example of taking an instance named i-12345678 and resizing it to Medium:

ec2-modify-instance-attribute.cmd i-12345678 -t c1.medium

Note that the “Instance Types” page on the AWS website contains the updated list of available Instance types, as well as their “API name” (the string that represents their size).

Happy resizing!

Update March 24th, 2011:

AWS now supports resizing the Instance through the web console - just right-click on your (stopped) Instance and select the “Change Instance Type” option. Keep in mind that the all of the above limitations still apply.