I though it will be useful for the online community for me to put up a quick start guide to Amazon EC2. Let me know of any erros or problem that you encounter. Cheers...
AWS Account Setup
First, you need to go to Amazon Web Services site to create an AWS account and sign up to both the Amazon EC2 and S3 services.
Once you have completed the signing up process, you need to get your AWS access identifiers. Move your mouse over the Your Web Services Account button and select the View Access Key Identifiers as shown below.
Record both Your Access Key ID and Your Secret Access Key as shown below. Put these information somewhere safe where only you or an authorised person can access them. For example:
- Your Access Key ID: 2B8WQAKHBMR2YBECYGGQ
- Your Secret Access Key: K65RrZP8yrqz+PxCLNI+feDkaOiWFy93+df+63lCF
At the bottom of the thsi key identifiers page there is theYour X.509 Certificate section. Click the Create New button to create a new X.509 certificate . Then, download the certificated and put it in a safe directory. In my case, it's in C:\ec2-keys directory.
You should end up with a PEM-encoded X509 certificate and a private key file named as per the examples below:
SSH Client Setup (puTTY)
Next, you need to install an SSH client. Create a directory called putty in C:\Programs Files. Download the these PuTTY applications: PuTTY client, PuTTYgen and PSCP, and save them in the C:\Program Files\putty directory.
Then in the System variables section, click on the Environment Variables button to open the window as shown below.
Scroll down to find Variable named Path and select it. Click Edit, and add the PuTTY directory at the end of the current Path value as shown below. Click OK and close the System Properties windows.
I'm using the ElasticFox Firefox plugin to manage my Amazon EC2 instances. Download and install ElasticFox from here, then restart Firefox.
Run the ElasticFox plugin. You should get a screen that looks like below.
Click on Credentials located on the top left corner of the ElasticFox interface. We need to put in our AWS identifiers. Enter any Account Name that you like, and then your AWS Access Key and AWS Secret Access Key. Click Add to save your details, and close the window.
Now, click on Account IDs and enter your account ID (the 12 digit number without the hyphens) and any Display Name you like. So, if your ID is 4952-1993-3132, the you should enter 495219933132. Click Add and close the window.
Next, we need to create an SSH key pair to be used when we perform SSH remote login to an AWS instance. In ElasticFox, select the Keypairs tab. Then click on the green Create a New Keypair button. Enter any keypair name you like and click OK. You'll be prompted to save the generated keypair. Give a name (*.pem file extension), and save the keypair to a location (in my case its C:\ec2-keys\foc2-keypair.pem). The newly created keypair name will appear on the screen as below.
The newly generated keypair need to be changed to a format that can be understand by puTTY. We will use puTTYgen to do this. Run puTTYgen (remember where you saved it before! In my case its C:\Program File\putty\puTTYgen.exe). Then load the key that you saved before. You will be informed when the keypair has been successfully loaded.
Click on the Save private key button to save the puTTY compatible key (*.ppk file extension). Choose Yes when it the puTTYgen warning appear. In my case, I saved it to the C:\ec2-keys\foc2-keypair.ppk. Close puTTYgen once the file has been saved.
Now, we need to tell ElasticFox where to find the key. Back to ElasticFox, click on Tools and change the SSH Key Template match the location where you saved the keypair file.
Next, we need to setup the permission for external access to our amazon instance. At this stage, I'm only going to open permission for port 80 (http server) nas port 22 (SSH client). On ElasticFox, select the Security Group tab.
In the Group Permissions section, click the green Tick button to grant a new permission. The following window should appear, and enter the first port which is port 80 as below.
Click add, and repeat the same procedure for port 22. The newly created permission should appear on the permission list once created.
Now that you've finished with the setup, we are going to try to run an instance.
Running an InstanceIn ElasticFox, select the AMIs and Instances tab. In the Machine Images (AMIs) section, click on the blue Refresh button to list all the available public AMIs. The window should appear like below.
In this example, we're going to run a base install of Linux Ubuntu Hardy created by the excellent Alestic people. As shown below, enter hardy in the test box in the Machine Images (AMIs) section. This will list down all the available Ubuntu Hardy AMIs.
Select the latest Ubuntu Hardy AMI, in this example I am selecting AMI ID ami-6a57b203 (alestic/ubuntu-8.04-hardy-base-20080517.manifest.xml). Right click on the AMI, and select Launch instance(s) of this AMI. The following window will appear. Select your keypair in and click on Launch.
The launched instance will appear in the Your Instances section. Wait until the instance status changed to running. Keep refreshing the window (click the blue refresh button ) to update the status.
Once you instance is running, right click over your instance and select SSH to Public DNS Name. This is to connect to your instance via SSH using puTTY. If everything was setup properly, you should get the following screen.
CONGRATULATIONS!!! You have successfully run an instance and remote login to it via SSH. You're now free to do whatever you like to the instance. Just consider it as your own Linux PC that you can install any applications (Apache web server, MySQL etc).
If you need to create a webserver with PHP & mySQL (LAMP server) with an amazon instance, have a look at my LAMP server guide here.
And if you would like to set up a web server and mySQL cluster in Amazon EC2, have a look at my cluster guide here.
Savings Your Instance
First, we need to copy the PEM certificate and key files to the running instance. We will use PSCP to do this. Make sure that you know the location and the names of your
- keypair file (eg. C:\ec2-keys\foc2-keypair.ppk)
- AWS certificate file (eg. C:\ec2-keys\cert-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem)
- AWS private key file (eg. C:\ec2-keys\pk-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem)
In my example, the Public DNS is ec2-67-202-32-74.compute-1.amazonaws.com
Open the windows command prompt (Start->Run->Open: "cmd"). Then enter the following commands:
pscp -i <your keypair file> <your aws certificate file> <your aws private key file > root@<your public dns>:/mnt
In my example the command will be
pscp -i C:\ec2-keys\foc2-keypair.ppk C:\ec2-keys\cert-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem C:\ec2-keys\pk-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem
Note that I'm copying the files to the /mnt directory in the running instance.
Now connect again to the running instance using PuTTY and go to the /mnt directory. Both the certificate and private key file should be there.
Now, we need to create the currently running instance image. Enter the following command on the PuTTY client
ec2-bundle-vol -d /mnt -c <your aws certificate file> -k <your aws private key file> -u <your aws account number> -r i386 -p <your image name>
ec2-bundle-vol -d /mnt -c cert-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem -k pk-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem -u 495219933132 -r i386 -p my_hardy
It should now start creating the image as shown below. This may take a few minutes.
Once the image has been created, we are going to copy the images to Amazon S3 storage facilities. The command to do that is as below.
ec2-upload-bundle -b <s3 bucket name> -m /mnt/<your image name>.manifest.xml -a <access key id> -s <secret access key>
ec2-upload-bundle -b arope_ami -m /mnt/my_hardy.manifest.xml -a 2B8WQAKHBMR2YBECYGGQ -s K65RrZP8yrqz+PxCLNI+feDkaOiWFy93+df+63lCF
If you have an Access Denied error, it's possible that the bucket name that you enter is already exist. Try different bucket name.
Once the images has been copied successfully, we are going to use ElasticFox to register the AMI. To do this, in the Machine Images (AMIs) click on the green + button, a small window will prompt you to enter the AMI manifest path. The path entered should be in the following format: <s3 bucket name>/<your image name>.manifest.xml
Your new AMI should appear in the list now and you can run as many of these AMI instances as you like.
That's all, let me know for any errors and I'll put up some more guides as well. Watch this space.