Utility Grid Cloud Computing Tutorials and Resources

Part Five: Creating an Image

To store your server’s state (once it’s all set up), you can create an image of it and store it in S3. After doing this, you can launch the image as an instance (or fifty bajillion instances if you so choose).

First, make sure the cert-#.pem and pk-#.pem files are in your root directory.

We begin with

scp -i id_rsa-gsg-keypair pk-#.pem cert-#.pem root@your_public_dns.amazonaws.com:/mnt

Replace # with the filename and “your_public_dns” with… well, the public dns for this instance.

Next, we’ll bundle this thing.

ec2-bundle-vol -d /mnt -k /mnt/pk-#.pem -c /mnt/cert-#.pem -u account_id -r i386 -p the_image_name

Replace # with the filename.

Note: Replace “account_id” with your account number (don’t include the “-”).

And upload it onto S3. At this point you will be charged for storage.

ec2-upload-bundle -b very_unique_id -m /mnt/the_image_name.manifest.xml -a access_key_id -s secret_access_key

Replace “very_unique_id” with the bucket name. This can’t someone else’s existing bucket so use a unique name.

Note: The “access_key_id” and “secret_access_key” can be found in your AWS account.

Finally, we have to register this image with Amazon. If you try to run from your EC2 instance, you may get a “command not found” message. ec2-register is part of the API tools (as opposed to the AMI tools). If this happens, you can just run it from your local computer (as explained here).

ec2-register very_unique_id/the_image_name.manifest.xml

Replace “very_unique_id” with the bucket name and “the_image_name” with what you chose above. You will be given an image ID. You can use this to filter the AMI’s in ElasticFox to find your new AMI - and it’s ready to launch!

Part Four: Assigning a Domain Name

Now, we will make a domain name point to our machine in the cloud. For this part of the tutorial, I’m using “everydns.com” for dynamic dns. There are a number of solutions available. This one is free so anyone can follow along.

First, login to wherever your domain name is (for instance, godaddy.com) and edit the nameservers. Change your nameservers to ns(1 through 4).everydns.net and apply.

Go to everydns.com and create an account.

After successfully logging in, add a new domain using their sidebar. After adding it, click on it in the list.

If you can, delete any existing records. You won’t need them anymore.

Remember that ElasticIP we created earlier? It’s back in ElasticFox under the “Elastic IP” tab. Get that into your clipboard.

In everydns, add an A record with this IP and your domain name (without “www”)

Add a cname record for “www” with the record value being the domain you just entered.

Your domain will now point to the correct IP for that server instance. After a few hours, clear your DNS caches and type in the url. It will be the same page we saw in part three after typing in the IP.

Part Three: Persistant Storage

Think of your EC2 instances (the virtual computer we just made) like a RAM drive. If you ever need to reset it, it reverts to it’s original structure. This means databases and changed files will go back to normal. One way to make dynamic data persist regardless of the state of your EC2 instances is to add a virtual hard drive. If you don’t need to store persistant data, skip to step four. Otherwise, click on the “Volumes and Snapshots” tab.

Click the plus icon to create a new volume. For “Availability Zone” choose the same one as the image you will attach the drive.

This can be found under the “AMIs and Instances” tab. While you’re there, right click and choose “Copy Instance ID to clipboard”.

Now, from the “Volumes and Snapshots” tab, right click on your new volume and select “Attach this volume”. Paste the instance ID (or select it from the dropdown) and give your volume a name. After clicking attach, it’s status will change to “in-use”.

SSH into your machine instance and type:

mkfs.ext3 /dev/sdh

This will format the new partition.

mkdir /ebs; mount -t ext3 /dev/sdh /ebs

to mount the volume to the path “/ebs”. You should also

vi /etc/fstab

and add this volume (as shown). You can use:

echo "/dev/sdh /ebs ext3 noatime 0 0" >> /etc/fstab

to do this (thanks to Grig for this)

This path “/ebs” (or whatever you called it) is now available to any application. It will persist even if the machine is deleted. Just bring up a new instance, and remap the drive. You can even create snapshots of the drive’s state by right clicking on the volume and selecting “Create a new snapshot from this volume”.

Part Two: Make a computer

To create a machine instance, we will need to connect to our Amazon account with ElasticFox (for Firefox). Do a Google search - you’ll find it. Download and install the plugin. You will be asked to restart Firefox.

After restarting, click on “Elasticfox” from the “Tools” menu.

You will see something like this. “A” is where you can find images of machines. “B” is your current machines. Click on “Credentials” in the top left to add your Amazon account.

Give this account any name you like. The two keys are the Access Identifiers from your Amazon account. Click “Add” then “Close”.

Now, click on the “KeyPairs” tab. Add a keypair with a specific name.

A .pem file will be saved to your hard drive. Place this in a memorable spot as you will need to access it in just a few steps.

Click on the “Security Groups” tab. Add a group and give it any name and description that you like.

In the panel below, click the checkmark to add a permission. This initial permission will go from port 0 to 80. You click the checkmark again to add more ports if you know you’re going to need them (like 10000 for webmin)

Download putty. You’re going to need it to access your virtual computer. Just Google putty and click one of the downloads. For this tutorial, I will use the installer version. After downloading, run the installer.

Now, run PuttyGen from your newly installed Start Menu group.

Click “Conversions” and “Import Key”. You must select the key you saved a few steps before.

Click “Save private key” and place the file in your user directory under a folder called ec2-keys. For example “C:\documents and settings\username\ec2-keys\name.ppk”

With that file in place, return to ElasticFox and click on “Tools” in the upper right corner.

Make sure to change the SSH Key Template directory to whatever you chose when you saved your PPK file. Leave ${keyname} as it is simply a variable that changes depending on which machine you are connecting to.

We are now ready to create a virtual computer.

Click on “Refresh” under the “AMIs and Instances” tab if you don’t see anything listed. Each item in this list is an image of a computer just waiting to be activated in your cloud.

For example, type “apache” into the small input just above the list. This will filter the items leaving us with a smaller list. Right click on “ec2-public-images/fedora-core4-apache-mysql-v1.07″ if it is available and select “Launch Instance(s) of this AMI”.

Choose m1.small. You can make a stronger computer by selecting a different option. Adjust your security groups by removing default (if it’s there) and adding the group you made earlier (in this case “web_traffic”). Make sure to use the keypair (which became a pem, which became a ppk) from before.

Now, in “Your Instances” a machine will appear. It will say pending for about thirty seconds. Click “refresh” and your computer should say “ready”. Right click on this new machine and click “SSH to Public DNS Name”.

Putty will pop open. Add the rsa2 fingerprint to Putty’s cache.

We are now logged in to our fresh new (albeit virtual) computer.

Back from ElasticFox, right click on the new instance and select “Copy Public DNS Name to Clipboard”. Paste this into the URL of a new tab. This test page is being served from your new machine within the Amazon cloud.

To prove it, go back to putty and type:

vi /var/www/html/index.php

Then:

i

to edit this document then type in anything you like.

When you are done, hit escape then:
:wFinally type:

:q

to quit.

Refresh the tab you opened earlier with your Public DNS Name and you will should see it change.

From ElasticFox, click on the “Elastic IPs” tab. Click on the plus icon to add an elastic IP.

From the AMIs and Instances tab, right click on your new machine instance again. Select “Copy Instance ID to clipboard”. Go back to the “Elastic IPs” tab, right click on your new IP and choose “Associate this address”.

Paste in the instance name.

After a few minutes (took about ten for me), you can access your machine through this new IP.

Part One: Enter the cloud.

First, sign up for an account.

Add a way to pay. Your costs will vary (if you accidentally add five thousand large server instances for example).

Remember, everything past this point could potentially cost you money. On my first day using it, I was charged about $1.30. Not much of an investment on the front end.

Now, click on “Access Identifiers”

Remember this location. The Access Key ID and your Secret Access Key will be used to identify your account from this point on.

Just below these keys, you will have to create an X.509 certificate. Click “create new” to begin.

Now, download these newly generated private key files to location that you will remember. You need will need both files.

You are now set up with all the Amazon access keys you’ll need. This means we can sign up for the Elastic Compute Cloud. Click on “Products” and “Amazon Elastic Compute Cloud”. Then click “Sign Up”

To verify that it worked, click on “Your Account” then “Account Activity”. You should see two items listed with a cost of zero.

We are ready to create a virtual computer.