Sunday, November 20, 2011

Elastic IP Addresses

Each time the amazon instance is restarted it gets a different public DNS entry and IP address. In order to to get a permanent IP address associated with the instance I had to create what is known as an elastic IP address in AWS parlance. This required creating the elastic IP and associating with existing instance. Also the association of instance with elastic IP address needs to be done during startup of the instance:


  • Installed amazon api tools on the instance. I had to scp the zip file to the instance to proceed with the installation:

scp -i ~/aws/keys/thejus.pem ./aws/ec2-api-tools.zip ubuntu@ec2-107-22-175-254.compute-1.amazonaws.com:/home/ubuntu/.

  • Installed JDK 6 on the Amazon instance:

sudo apt-get install openjdk-6-jdk

  • Added these entries to .bashrc for the api variables to take effect:


export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
export EC2_HOME=/home/ubuntu/aws/ec2-api-tools-1.4.4.2


export PATH=$JAVA_HOME/bin:$EC2_HOME/bin:$PATH


export EC2_KEY_DIR=/home/ubuntu/aws/keys
export EC2_PRIVATE_KEY=${EC2_KEY_DIR}/pk-Y36R3VDKYF55PYKVXR3VFGSNCY7AQGLS.pem
export EC2_CERT=${EC2_KEY_DIR}/cert-Y36R3VDKYF55PYKVXR3VFGSNCY7AQGLS.pem


  • Quick check to verify that the changes are working:



ubuntu@domU-12-31-38-01-86-A5:~$ ec2-describe-regions
REGION  eu-west-1       ec2.eu-west-1.amazonaws.com
REGION  us-east-1       ec2.us-east-1.amazonaws.com
REGION  ap-northeast-1  ec2.ap-northeast-1.amazonaws.com
REGION  us-west-2       ec2.us-west-2.amazonaws.com
REGION  us-west-1       ec2.us-west-1.amazonaws.com
REGION  ap-southeast-1  ec2.ap-southeast-1.amazonaws.com

  • Create the auto-startup script for startup during boot up:
/etc/init.d$ vi ec2-startup
#!/bin/bash

export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
export EC2_HOME=/home/ubuntu/aws/ec2-api-tools-1.4.4.2
export EC2_KEY_DIR=/home/ubuntu/aws/keys
export EC2_PRIVATE_KEY=${EC2_KEY_DIR}/pk-Y36R3VDKYF55PYKVXR3VFGSNCY7AQGLS.pem
export EC2_CERT=${EC2_KEY_DIR}/cert-Y36R3VDKYF55PYKVXR3VFGSNCY7AQGLS.pem

export PATH=$JAVA_HOME/bin:$EC2_HOME/bin:$PATH

elastic_ip=107.22.175.254
instance_id=i-72fb9e12

start() {

        /bin/echo "associating elastic IP address..."
        ec2-associate-address $elastic_ip -i $instance_id
}


stop() {
        /bin/echo "disassocating elastip IP address..."
        ec2-disassociate-address $elastic_ip
}
case "$1" in
        start) 
                start
                ;;
        stop)  
                stop
                ;;
        restart)
                stop
                sleep 5
                start
                ;;
        *)
                echo "Usage: $SELF {start|stop|restart}"


esac


exit 0


  • Update ubuntu settings to execute script during startup:


/etc/init.d$ sudo update-rc.d ec2-startup defaults
update-rc.d: warning: /etc/init.d/ec2-startup missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
 Adding system startup for /etc/init.d/ec2-startup ...
   /etc/rc0.d/K20ec2-startup -> ../init.d/ec2-startup
   /etc/rc1.d/K20ec2-startup -> ../init.d/ec2-startup
   /etc/rc6.d/K20ec2-startup -> ../init.d/ec2-startup
   /etc/rc2.d/S20ec2-startup -> ../init.d/ec2-startup
   /etc/rc3.d/S20ec2-startup -> ../init.d/ec2-startup
   /etc/rc4.d/S20ec2-startup -> ../init.d/ec2-startup
   /etc/rc5.d/S20ec2-startup -> ../init.d/ec2-startup
  • Verify that the elastic IP address is associated with the instance with a restart of the ec2 instance:
$ ec2-stop-instances i-72fb9e12INSTANCE i-72fb9e12 running stopping

$ ec2-describe-instances
RESERVATION r-cedf27a0 880425318169 default
INSTANCE i-72fb9e12 ami-00b14b69 stopped thejus 0 t1.micro 2011-11-15T06:22:25+0000 us-east-1b aki-825ea7eb monitoring-disabled ebs paravirtual xen sg-d72124be default
BLOCKDEVICE /dev/sda1 vol-59c48233 2011-11-21T04:44:49.000Z
TAG instance i-72fb9e12 Name ubuntu-server

$ ec2-start-instances i-72fb9e12
INSTANCE i-72fb9e12 stopped pending

$ ec2-describe-instances
RESERVATION r-cedf27a0 880425318169 default
INSTANCE i-72fb9e12 ami-00b14b69 ec2-107-22-175-254.compute-1.amazonaws.com domU-12-31-38-04-22-9C.compute-1.internal running thejus 0 t1.micro 2011-11-21T04:46:13+0000 us-east-1b aki-825ea7eb monitoring-disabled 107.22.175.254 10.220.33.102 ebs paravirtual xen sg-d72124be default
BLOCKDEVICE /dev/sda1 vol-59c48233 2011-11-21T04:46:33.000Z
TAG instance i-72fb9e12 Name ubuntu-server


Monday, November 7, 2011

Installing Rails on EC2

Mainly followed the steps outlined in this article to install Ruby on Rails:

http://blog.sudobits.com/2011/10/27/how-to-install-ruby-on-rails-in-ubuntu-11-10/

I did have to update the package list once to download all the dependent packages.

To get rails 3.1.1 working on ubunut I had to install javascript runtime (http://railsapps.github.com/installing-rails-3-1.html):

sudo apt-get install nodejs

Also, open port 3000 to allow testing of the rails installation:

$ ec2-authorize web -P tcp -p 3000 -s 0.0.0.0/0

Saturday, October 15, 2011

Stopping and Starting Instance to Migrate to New Hardware

Received an email that my amazon instance is running on a host that is running on degraded hardware and will be brought down for maintenance. All I was asked to do was to stop and start my instance to migrate instance to new hardware.

So I issued the following command to stop:

~$ ec2-stop-instances i-22222
INSTANCE i-22222 running stopping

The status on the AWS console and from the command line said the instance is stopping:


~$ ec2-describe-instances


Got this message after issuing the start command:

~$ ec2-start-instances i-22222

Client.IncorrectInstanceState: The instance 'i-22222' is not in a state from which it can be started.

After waiting for approximately ten minutes, the instance was stopped and I issued the start command again:


t~$ ec2-start-instances i-22222
INSTANCE i-22222 stopped pending


The instance was started successfully.

Sunday, September 25, 2011

Getting Command Line Access to Amazon EC 2 / Web Service

After signing up for the AWS account, did the following steps to get started with command line access to my instance:
$ sudo apt-get install sun-java6-jdk
  • Added the following to .bashrc for the EC2 environment variables: 
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.26
export EC2_HOME=/home/thejus/aws/ec2-api-tools-1.4.4.2
export AWS_RDS_HOME=/home/thejus/aws/RDSCli-1.4.007

export PATH=$JAVA_HOME/bin:$EC2_HOME/bin:$AWS_RDS_HOME/bin:$PATH

export EC2_KEY_DIR=/home/thejus/aws/keys
export EC2_PRIVATE_KEY=${EC2_KEY_DIR}/pk-Y36R3VDKYF55PYKVXR3VFGSNCY7AQGLS.pem
export EC2_CERT=${EC2_KEY_DIR}/cert-Y36R3VDKYF55PYKVXR3VFGSNCY7AQGLS.pem
  • Run this command to verify that the command line tools are set up:
$ ec2-describe-regions 

REGION eu-west-1 ec2.eu-west-1.amazonaws.com
REGION us-east-1 ec2.us-east-1.amazonaws.com
REGION ap-northeast-1 ec2.ap-northeast-1.amazonaws.com
REGION us-west-1 ec2.us-west-1.amazonaws.com
REGION ap-southeast-1 ec2.ap-southeast-1.amazonaws.com

  • Launch the instance from the AWS management console: I selected the ubuntu server instance type instance: i-72fb9e12 (ubuntu-server), mainly to stay within the free tier limit, along with the micro type.
  • Download the key during the instance creation process and save in key directory.
  • Run this command to check the status of the instance once started:
$ ec2-describe-instances
  • Enable ssh connectivity to the instance using this command:
$ ec2-authorize default -p 22 -s 0.0.0.0/0
  • Once the instance is in a running state connect to the instance using ssh: 
$ ssh -i thejus.pem ubuntu@ec2-72-44-48-18.compute-1.amazonaws.com


If you see the ubuntu command prompt on the Amazon instance then you are successfully logged in!

Monday, September 19, 2011

AWS Free Usage Tier

Going to sign up for Amazon Web Services and hopefully stay within the free tier limit to avoid a charge to my CC which Amazon verified during the signup process:

AWS Free Usage Tier (Per Month):
  • 750 hours of Amazon EC2 Linux Micro Instance usage (613 MB of memory and 32-bit and 64-bit platform support) – enough hours to run continuously each month*
  • 750 hours of an Elastic Load Balancer plus 15 GB data processing*
  • 10 GB of Amazon Elastic Block Storage, plus 1 million I/Os, 1 GB of snapshot storage, 10,000 snapshot Get Requests and 1,000 snapshot Put Requests*
  • 5 GB of Amazon S3 standard storage, 20,000 Get Requests, and 2,000 Put Requests*
  • 15 GB of bandwidth out aggregated across all AWS services*
  • 25 Amazon SimpleDB Machine Hours and 1 GB of Storage**
  • 100,000 Requests of Amazon Simple Queue Service**
  • 100,000 Requests, 100,000 HTTP notifications and 1,000 email notifications for Amazon Simple Notification Service**
  • 10 Amazon Cloudwatch metrics, 10 alarms, and 1,000,000 API requests**
In addition to these services, the AWS Management Console is available at no charge to help you build and manage your application on AWS.

I should remember to stop the instances when I am not using them.

Delving into the Cloud

I am creating this blog to blog about my experiences as I delve into the world of cloud computing. My goal is to write about the different options and architectures on the cloud computing front with a practical implementation. Specifically, I will keep a journal of day to day activities of actually implementing a site on cloud, do research on different cloud computing platforms and architectures and review the pros and cons of implementation on a cloud versus hosting ones own infrastructure.

I propose to start with Amazon Cloud since it is one of the most popular cloud computing platforms. After a quick implementation, a sort of a proof of concept, I will look into the security, scalability and reliability aspects of the cloud platform. I also plan on doing a similar installation on other cloud platforms as and when they present themselves.