Amazon EC2 – a first look

EC2 stands for Elastic Compute Cloud. It is a web service that enables you to launch and manage Linux/UNIX and Windows server instances in Amazon’s data centers using APIs or available tools and utilities. You can use these instances to do all kind of things. Say you’re hosting a website and suddenly your site gets popular, you can then instantiate a few more instances to help balance the load. When the visitors then stop to visit your website, you can cut down on the instances, and you’re not left with any server hardware you can’t use.

As ADA ICT is a progressive company, they wanted to know what Amazon EC2 could offer to them. A colleague of mine and myself we’re asked if we could check it out.

Set up your account
First of all you have to make an account, read this to set one  up. Create an S3 account and a EC2 account. As stated in the tutorial write down you AWS account’s Access Key ID and Secret Access Key. As I am going to use the Command Line Tools (CLT), I also have to get some certificates to get access to my account. You can read here how to get them (see the section “Getting your access Key Identifiers”).  Place them in a directory on your hard disk. It is important that this directory name has no spaces in it.

Prerequisites
There are some prerequisites you need to set up before you can use the CLT. First is Java. If you don’t have the Java Runtime Environment installed, download it here. Then setup an environment variable on you system called JAVA_HOME, this variable has to point to your Java directory in which is a bin directory with a java.exe file in it.

Now get your CLT here. Just unzip them in a directory of your choice. These tools depend on an environment variable called EC2_HOME, so just as you created your Java variable, create a EC2_HOME variable which points to directory you chose to install your CLT. Also add the BIN directory of this directory to your PATH variable.
We have to tell the tools who we are (because nothing stops you from having multiple AWS Accounts), so we going to create 2 new environment variables called EC2_PRIVATE_KEY and EC2_CERT, these have to point to your certificates (not the directory) you downloaded earlier (section set up your account), the EC2_PRIVATE_KEY has to point to your certificate which starts with pk, and the EC2_CERT variable to your file which starts with cert.

So now we are in business.
Cause we are situated in the Netherlands, we had to change our region to Europe. This can be done with the following commands

  1. first get the available regions: 

    ec2-describe-regions

    This will return: 

    REGION us-east-1 us-east-1.ec2.amazonaws.com
    REGION eu-west-1 eu-west-1.ec2.amazonaws.com

    The first is your current region.

  2. To change your region, execute the following command:  

    set EC2_URL=https://eu.west-1.ec2.amazonaws.com

We can now find an AMI (Amazon Machine Image) as a base of our system we need to build. You can browse for available images here, or you could issue the command:

ec2-describe-images –o self –o amazon 

Amazon offers different types of instances: small, Large and Extra Large.
A small instance is default and has 1.7GB of memory, 1 virtual core and 160gb of storage and suitable for a 32 bits Operating System.
A large instance had 7,5GB of memory, 2 virtual cores and 850gb of storage and is a base for a 64 bits OS.
The Extra Large instance had 15Gb of memory, 4 virtual cores and 1690GB of storage and is also for a 64 bits OS.
Keep in mind that 10GB of the disk storage is used for the OS, and if you bundle the AMI (we’ll get to that later), is persistent storage. The rest is storage which will be gone when you shutdown the image, for that you have to create an EBS volume.
There are also some high cpu instances, with more virtual cores.

Ok, I found my AMI. I needed a Windows 2003 server for a small instance (32 bits), which does not have authentication services (meaning: Active Directory). This is the one. Write down the AMI ID (the Europe AMI ID, as I live in the Netherlands, so this is ami-7acae20e).

We now have to generate a key pair, because the AMI is a public image and has no password. To login to this image I need a public / private key pair. To generate one, enter the following command:

ec2-add-keypair gsg-keypair

Amazon now returns a key pair, like this:
KEYPAIR gsg-keypair
1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f
—–BEGIN RSA PRIVATE KEY—–
MIIEoQIBAAKCAQBuLFg5ujHrtm1jnutSuoO8Xe56LlT+HM8v/xkaa39EstM3/
aFxTHgElQiJLChp
HungXQ29VTc8rc1bW0lkdi23OH5eqkMHGhvEwqa0HWASUMll4o3o/IX+0f2UcPoKC
+jx71Sg
5AU52EQfanIn3ZQ8lFW7Edp5a3q4DhjGlUKToHV………………………..

Just copy the part starting from BEGIN RSA PRIVATE KEYuntil END RSA PRIVATE KEY (!!including these tags), save it to a file for example id_rsa-gsg-keypair.

We can now launch our Ami with the following command:

ec2-run-instances ami-7acae20e –k gsg-keypair

Amazon will return to you some output, behind the text INSTANCE you will find your Instance ID, write this one down (let’s say it is: i-ab1cd2d3). It will take some time for your instance to launch. You can see the status of the instance with the following command (your instance is started when it returns running):

ec2-describe-instances iab1cd2d3

We now gonna authorize our network to connect to the instance by use of RDP. Execute the following command:

ec2-authorize default –p 3389 –s 80.124.112.224/32 

In which the ip address behind the –s parameter is your external ip interface, if you don’’t know it you can find it here. Last part is to get our password to login to windows. The following command will return your windows password:

ec2-get-password –k id_rsa_gsg-keypair i-ab1cd2d3

Now get the DNS name you need to connect to:

ec2-describe-instances i-ab1cd2d3

It will return the dns name you need for connecting to your instance by use of RDP, it will look like this <something>.eu-west-1.compute.amazonaws.com

That’s it. Not that hard I believe.
I am still going to look into bundeling my image (so I can shut it down, and start it with all the changes I made), firewall, EBS volume, etc…..

We did have one issue’s, when following this guide.
it was the error:
“Client.InvalidParameterValue: The requested instance type’s architecture (i386) does not match the architecture in the manifest for ami-abcdefgh (x86_64)”.
This is because we first choose a wrong AMI. This was a 64 bits AMI and we did not specify to run a large or extra large instance (parameter –instance-type), it will then default a small instance.

One thought on “Amazon EC2 – a first look

  1. Pingback: Amazon EC2 – Getting started with an Instance

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>