Boto for Amazon Route53

Tips N Tricks August 20th, 2011

Route53 is Amazon’s scalable Domain Name System (DNS) web service. If you are already having your infrastructure on Amazon’s EC2 infrastructure, it is an easy move from your existing DNS provider to Route53.

Boto is a python package that provides a number of python interfaces to interract with Amazon Web Services (AWS) like EC2, RDS, ELB, etc. Boto interface for Route53 is pretty simple. Boto allows adding ‘A’, ‘AAAA’, ‘TXT’, ‘CNAME’, ‘MX’, ‘PTR’, ‘SRV’ and ‘SPF’ records to Route53.

Each zone that is created on Route53 has a zone id which can be obtained by using the command line utility provided by amazon.

% ./bin/route53 ls
============================================
| ID: ZXXXXXXXXXXXXXX
| Name: yourdomain.com.
| Ref: xxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxxxx
============================================
{}

Basic authentication on boto for Route53

The following step is required for all boto operations with route53. In python terminal use the following commands:

>>> import boto
>>> from boto import route53
>>> key = ‘AAES5WCQQBW5XZ2DAA’
>>> access = ‘DMJsjdlkr0OHnrwqEsGkksjweosbg/yeISOPEOdnsK’
>>> route53 = Route53Connection(key, access)
>>> results = route53.get_all_hosted_zones()
>>> results
{u’ListHostedZonesResponse’: {u’HostedZones’: [{u'CallerReference': u'6000r000-b00-0000-8000-46000000c', u'Config': {}, u'Id': u'/hostedzone/ZXXXXXXXXXXXXXX', u'Name': u'yourdomain.com.'}], u’IsTruncated’: u’false’, u’MaxItems’: u’100′}}

Adding A record on Route53 with Boto

>>> import boto
>>> from boto.route53.record import ResourceRecordSets
>>> conn = boto.connect_route53(key, access)
>>> changes = ResourceRecordSets(conn, “ZXXXXXXXXXXXXXX”)
>>> change = changes.add_change(“CREATE”, “yourdomainname.com”,”A”)
>>> change.add_value(“45.34.22.455″) #your ip address
>>> changes.commit()

Adding CNAME on Route53 with Boto

>>> import boto
>>> from boto.route53.record import ResourceRecordSets
>>> conn = boto.connect_route53(key, access)
>>> changes = ResourceRecordSets(conn, “ZXXXXXXXXXXXXXX”)
>>> change = changes.add_change(“CREATE”, “subdomain.yourdomainname.com”, “CNAME”)
>>> change.add_value(“some_dns_name”)
>>> changes.commit()

Adding TXT Record on Route53 with Boto

Note: All text records will require you to add strings as value. Note the extra quotes around the text value, else expect to see an error as below:

Invalid Resource Record: FATAL problem: InvalidTXTRDATA encountered at “\”v=spf1 ip4:64.64.9.245 a mx ~all\”

>>> import boto
>>> from boto.route53.record import ResourceRecordSets
>>> conn = boto.connect_route53(key, access)
>>> changes = ResourceRecordSets(conn, “ZXXXXXXXXXXXXXX”)
>>> change = changes.add_change(“CREATE”, “yourdomainname.com”, “TXT”)
>>> change.add_value(“\”v=spf1 mx ptr include:mail and other text a ~all\”“)
>>> changes.commit()

Deleting CNAME on Route53 with Boto

>>> import boto
>>> from boto.route53.record import ResourceRecordSets
>>> conn = boto.connect_route53()
>>> changes = ResourceRecordSets(conn, “ZXXXXXXXXXXXXXX”)
>>> change = changes.add_change(“DELETE”, “subdomain.yourdomainname.com”, “CNAME”)
>>> change.add_value(“some_dns_name”) #Note: This value has to match exactly with the record
>>> changes.commit()

Invalid shift value in prefixCoded string (is encoded value really a LONG?)

Tips N Tricks August 20th, 2011

Spatial search on documents can be performed using solr and the jteam plugin. Jteam pdf documentation is clear and a good starter.

After installing the plugin in solr and changing the required entries in solr.xml and solrconfig.xml, a spatial query resulted in the following error.

HTTP ERROR: 500

Invalid shift value in prefixCoded string (is encoded value really a LONG?)

java.lang.NumberFormatException: Invalid shift value in prefixCoded string (is encoded value really a LONG?)
at org.apache.lucene.util.NumericUtils.prefixCodedToLong(NumericUtils.java:206)
at org.apache.lucene.search.FieldCache$10.parseDouble(FieldCache.java:294)
at org.apache.lucene.search.FieldCacheImpl$DoubleCache.createValue(FieldCacheImpl.java:635)
at org.apache.lucene.search.FieldCacheImpl$Cache.get(FieldCacheImpl.java:224)
at org.apache.lucene.search.FieldCacheImpl.getDoubles(FieldCacheImpl.java:602)
at nl.jteam.search.solrext.spatial.lucene.LatLongLocationDataSetFactory.buildLocationDataSet(LatLongLocationDataSetFactory.java:35)
at nl.jteam.search.solrext.spatial.lucene.SpatialQuery$SpatialWeight.scorer(SpatialQuery.java:186)
at org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:297)

The solution was to delete the data folder (aka the indexes) and index the data again.

XAMPP Mysql and PHPmyAdmin Issues

Tips N Tricks February 3rd, 2010

After you install XAMPP using the tutorial steps provided here there are two common issues that can occur which would prevent the working of MySQL and PHPMyAdmin. Lets us tackle the two problems as follows.

Problem 1: XAMPP: Couldn’t start MySQL!

As suggested in the tutorial, you can start XAMPP server using /opt/lampp start and you are supposed to get the output as below:

Starting XAMPP 1.7.3a…
LAMPP: Starting Apache…
LAMPP: Starting MySQL…
LAMPP started.

But instead you might see something like below:

Starting XAMPP 1.7.3a…
LAMPP: Starting Apache…
LAMPP: Starting MySQL…
XAMPP: Couldn’t start MySQL!
LAMPP started.

Solution 1:
This is caused due to permission issues and you can solve it using the following steps.
a) In the terminal su to root : su
b) Provide the root password when prompted
c) chown -hR root /opt/lampp (Change the path as required)
d) chmod -R 777 /opt/lampp
e) /opt/lampp/lampp restart

This should give you an output something like :
Starting XAMPP for Linux 1.7.3a…
XAMPP: Starting Apache with SSL (and PHP5)…
XAMPP: Starting MySQL…
Warning: World-writable config file ‘/opt/lampp/etc/my.cnf’ is ignored
Warning: World-writable config file ‘/opt/lampp/etc/my.cnf’ is ignored
XAMPP: Starting ProFTPD…
XAMPP for Linux started.

Additional steps to be followed:

a) vi /opt/lampp/etc/php.ini
b) uncomment ; session.save_path = /tmp
to session.save_path = /tmp

Problem 2:
When you try to access mysql you would get an error as : “cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly”

If the above said problem was already solved then you might encounter the new problem which says,

“Wrong permissions on configuration file, should not be world writable!”.

Solution 2:
a) Open terminal
b) get root access
c) Change permission of config.inc.php file : chmod a-w /opt/lampp/phpmyadmin/config.inc.php

This solution worked on Mandriva 2007 spring running Gnome on Linux kernel 2.6.17-13mdv.

XAMPP: Apache, MySQL and PHP on linux

Tips N Tricks January 17th, 2010

For those who do not want to configure their own webserver, sql server and modules to quickly test a random PHP code, XAMPP provides an easy bundled package to get things up and running quickly.

Adding apache server in your linux installation is easy using XAMPP. It was earlier called LAMPP and is now being called the XAMPP. The understanding is that

it stands for X (linux), A (apache), M (mysql), Php (php).

This is a nice way to develop php websites locally on your computer before wanting to deploy it online. You can even make your server visible to the internet by putting XAMPP online and open to the Internet. Doing that will allow you to run your own server. Some help from DynDNS will help you map a domain name to the ip address of your XAMPP on your computer. These will not be discussed here but lets continue towards linux installation of XAMPP.

Steps :

1) Download the XAMPP package:

Download XAMPP.

2) (Important) Extract ONLY using the following command

sudo tar xvfz xampp-linux-1.7.3a.tar.gz -C /opt

Warning: Please use only this command to install XAMPP. DON’T use any Microsoft Windows tools to extract the archive, it won’t work.

Good News: XAMPP is now installed below the /opt/lampp directory.

3) Start the server using :

/opt/lampp/lampp start

Good News if you see :
Starting XAMPP x.x.x…
LAMPP: Starting Apache…
LAMPP: Starting MySQL…
LAMPP started.

4) Test the server by opening firefox and typing

http://localhost

The document root will be called “www” in the /opt/lampp folder.