Making EC2 Tools environment:
- Download and the command line tools from http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&categoryID=88 and extract at some place like: C:\ec2-api-tools-1.3-41620
- Login into your amazon EC2 account. Goto:
Your Account -> Security Credentials -> x.509 Certificates
make one and download to some place like C:\ec2 - Make sure that you have latest version of JRE installed on your local machine. Now use the following commands to set environment variables, (CHANGE THE PATHS TO YOUR PATHS):
set JAVA_HOME="C:\Program Files\Java\jdk1.6.0_11"
set EC2_HOME=C:\ec2-api-tools-1.3-41620
set PATH=%PATH%;%EC2_HOME%\bin
set EC2_PRIVATE_KEY=c:\ec2\pk-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem
set EC2_CERT=c:\ec2\cert-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem
Now we have our local machine ready to use EC2 commands.
Running and connecting to the instance
- Get a list of available amazon AMIs using this command
ec2-describe-images -o self -o amazon | grep fedora
We have applied the fedora filter as we want to use it. There is an apache-mysql fedora core4 AMI available as ec2-public-images/fedora-core4-apache-mysql.manifest.xml. We will be using this AMI. Note down its id, which is in this case: ami-25b6534c - Now we will be downloading our private RSA key to be used with this AMI. Run the following command in command prompt:
ec2-add-keypair gsg-keypairand save everything between these lines including these lines as “id_rsa-gsg-keypair”:
“—–BEGIN RSA PRIVATE KEY—–”
“—–END RSA PRIVATE KEY—–”
We want to use putty to communicate with this AMI. Our private key needs to be converted into putty format. Download puttygen.exe from http://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe open puttygen.exe, load id_rsa-gsg-keypair and save private key - Run the public AMI instance using this command:
ec2-run-instances ami-25b6534c -k gsg-keypairNOTE DOWN THE ID OF THE INSTANCE
- You can use this command to check the status of you instance. Note down the server address of the instance:
ec2-describe-instances i-548****(Replace i-548**** with you instance id)
- Now we need to open port 22 (for ssh) and port 80 (for http) on this instance. Run the following commands in command prompt.
ec2-authorize default -p 22
ec2-authorize default -p 80 - Enter the server address noted down in step 4 to your browser. You should see a default Fedora Core 4 Apache welcome page.
- Open putty; goto
Connection -> SSH -> Auth
browse for your private key you made using puttygen.Enter the sever address from step 4 to connect and use the username ‘root’ to login.
- Once successfully connected, you can use this instance like any other Linux server.
Configuring Server, Apache and mode_python
- Yum is already installed on this instance but it needs to be configured. Open the file /etc/yum.repos.d/fedora.repo and uncomment the baseurl line. Also change the url to http://archives.fedoraproject.org/pub/archive/fedora/linux/*****
Do the same with
/etc/yum.repos.d/fedora-updates.repo and
/etc/yum.repos.d/fedora-extras.repo - Update the list:
yum check-update - Use following commands to install some packages using yum:
yum install gcc
yum install httpd-devel
yum install python-devel - Now install mod_python using following commands:
cd /tmp
wget http://download.filehat.com/apache/httpd/modpython/mod_python-3.3.1.tgz
tar xvfz mod_python-3.3.1.tgz
cd mod_python-3.3.1
./configure
make
make install - mod_python is installed. Now we just need to add following lines to /etc/httpd/conf/httpd.conf to make it load with apache.
LoadModule python_module modules/mod_python.so
PythonOption mod_python.mutex_directory "/tmp"
PythonOption mod_python.mutex_locks 8
Saving the EC2 instance on S3
You will loose all settings and configurations as you will terminate the instance. We need to save instance as our own AMI at this stage.
- Download PSCP from http://the.earth.li/~sgtatham/putty/latest/x86/pscp.exe and run the following command in command prompt to transfer our X.509 certificate to the server for future use.pscp -i id_rsa-gsg-keypair pk-ZG273YPOU74KIXM3UGTDFAIWOARHSSVE.pem cert-ZG273YPOU74KIXM3UGTDFAIWOARHSSVE.pem root@ec2-67-***-***-***.compute-1.amazonaws.com:/mnt (Replace Server name and .pem file names/paths with your files.)
- Now we need to download AMI-Tools for backup of our instance. Go back to putty, log into the server as described before and run the following set of commands.
cd /tmp(Replace YOUR_AWS_ACCOUNT_ID with your account ID)
wget http://developer.amazonwebservices.com/connect/entry.jspa?externalID=368&categoryID=88
unzip ec2-ami-tools-1.3-34544.zip
cp -r ec2-ami-tools-1.3-34544/ /usr/local/
export EC2_AMITOOL_HOME=/usr/local/ec2-ami-tools-1.3-34544/
export PATH=$PATH:${EC2_AMITOOL_HOME:-EC2_HOME}/bin
ec2-bundle-vol -d /mnt -k /mnt/pk-ZG273YPOU74KIXM3UGTDFAIWOARHSSVE.pem -c /mnt/cert-ZG273YPOU74KIXM3UGTDFAIWOARHSSVE.pem -u YOUR_AWS_ACCOUNT_ID -r i386 -p mod_python
- This will take some time and will create image files in /mnt. Now we will upload these image files to S3 using this command
ec2-upload-bundle -b -m /mnt/image.manifest.xml -a -s
It will take some time. - Now we need to register our image so that AWS can locate it.
ec2-register /image.manifest.xml
You will get you AMI id, safe it for future use. - Now you can safely terminate your instance.
Installing django
- Use the following commands to install django:
cd /usr/local
svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk
ln -s `pwd`/django-trunk/django /usr/lib/python2.4/site-packages/django
ln -s /usr/local/django-trunk/django/bin/django-admin.py /usr/local/bin - Edit the httpd.conf at /etc/httpd/conf/httpd.conf and add following lines:
<Location “/mysite/”>
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonDebug On
PythonPath “['/path/to/project'] + sys.path”
</Location>
- Restart the apache and you are ready to go
















