Howto use Amazon Elastic Compute Cloud. (EC2)

While experimenting with Amazons interpretation of cloud computing, here is what I did to create persistent storage, create an instance and attach the storage to the instance.

Install and configure the local tools.

Go to Amazons developer section and download, unpack and install the files. Now edit ~/.bashrc (or any other file that is executed at login) and add this:

export EC2_HOME=~/.ec2
export PATH=$PATH:$EC2_HOME/bin
export EC2_PRIVATE_KEY=$(ls $EC2_HOME/pk-*.pem)
export EC2_CERT=$(ls $EC2_HOME/cert-*.pem)
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home/
export EC2_URL=

As you can see, I have the tools installed in ~/.ec2, the JAVA_HOME is set for a Mac OS X machine and I use the European Amazon infrastructure. Get a list of these regions with ec2-describe-regions.

Create a keypair.

Check out the wonderful section on Paul Stamatiou's website at "Getting Started". It describes how to create and use the keys.

Open ports 22 and 80.

You will have to authorize access from the internet to port 22 and 80, or any other. Here is how it's done:

ec2-authorize default -p 22
ec2-authorize default -p 80

default refers to all machines unless specified differently.
The option -p refers to a port number.

Create an instance.

An instance can be seen as an individual machine. It's virtual, but who cares about that? I use the image "ami-2a0f275e", but see other images can be used as well. Use ec2-describe-images -o amazon to get a list of available images owned (-o) by amazon.

ec2-run-instances -z eu-west-1a -k ec2-keypair ami-2a0f275e

The option -z specifies an "availability zone". Get a list of these zones with ec2-describe-availability-zones.
The option -k specifies what key to use. If you don't use this option, you will not be able to login using SSH.

Create a volume.

To allocate some space on the S3 infrastructure of Amazon, use this command:

ec2-create-volume -s 1 -z eu-west-1a

The option -s 1 specifies that the size is 1 Gib.
The option -z is used to determine the availability zone, it needs to match the instance's zone.

Attach the volume to the instance.

When the volume is created; assign it to an instance with this command:

ec2-attach-volume vol-38a24751 -i i-c2f2c5b6 -d sdb

This only makes the device available, you will have to partition, format and mount it to use it.
The argument vol-38a24751 describes the volume to attach. Use ec2-describe-volumes to get a list of available volumes.
The option -i specifies the instance. Use ec2-describe-instances to get a list of available instances.
The option -d specifies the name under which Linux will recognize the volume. Login to you machine, type dmesg to see if attaching has worked. This is the ouput I got:
dmesg | tail -n 1
sdb: unknown partition table

Logging into your instance

Login to your machine using SSH:

ssh -i .ec2-keypair [email protected]

The option -i specifies the identity to use.
The argument MACHINE needs to be replaces with the public DNS name of you instance. Get a list of the named using describe-instances.
If you like to type less; add this to your ~/.ssh/config file:
Host *
IdentityFile ~/.ec2/ec2-keypair
User root

From the moment on that you have added this configuration, you can simply login to your instance without any options, just the DNS name of the instance.

Formatting and mounting the volume.

Now that you are ready, login and type:

mkfs.ext3 /dev/sdb

Mount the volume (once) by issuing:

mount /dev/sdb /mnt

There is 924 Megabytes (Mb) available. so you'll lose some 80 Mb's for the filesystem.

Setting a static IP.

You can continue to use the instance with this "static" IP, but to associate one IP with this instance, follow these steps. First register an IP:


You will see the IP printed on your screen.

Now link the IP with an instance.

ec2-associate-address -i i-0ca09678


The Amazon elastic compute cloud and S3 facilities work great, I'm not sure about the availability of EC2, not about S3, but Amazon states that S3 should be more "secure" then storing stuff in the local storage of the instance.

About Consultancy Articles Contact

References Red Hat Certified Architect By Robert de Bock Robert de Bock
Curriculum Vitae By Fred Clausen +31 6 14 39 58 72
By Nelson Manning [email protected]