Using AWS SimpleDB with Railo and Tomcat

I’ve been working with Amazon Webservices (AWS) and needed to connect to it from some of our railo servers.

Getting Setup

Here is some documentation for reference and to help others:

1. Get the SDK from Amazon

2. Get the HTTPComponents Client

  • You will also need get the HTTPComponents Client from apache as it depends on this. I downloaded the 4.1.1 release and this worked a treat
  • Extract the 6 jars and drop them in your tomcat/lib folder.

3. Restart Tomcat and write some code

Comparison of techniques

I played with a few different techniques of using the AWS with tomcat and found the following:

1. CFHTTP direct API calls

This was based on a modified version of the AWS CF Console code. This has the benefit of being simple (none of the jar files were needed) and it took approx 900ms to do a query from Australia to US East AWS. From our US datacenter this took less than 30ms). However, this method had the significant drawback or requiring lots of code to be written to handle each function. Not good.

2. Java AWS SDK from Railo

I then did the steps above and used the AWS SDK from a test page using the following code:

<cfset awscreds = createObject("java","com.amazonaws.auth.BasicAWSCredentials").init(accessKeyId,secretAccessKey)>
<cfset sdb = createObject("java","").init(awscreds)>
<cfset selectReq = createObject("java","").init("select * from #domainName# where testid = '10000000'")>

This worked well, but each request took on average of 1500ms from AU to US East AWS. This was disappointing, so I tried caching in the the application scope as below.

3. Java AWS SDK cached in App Scope

<cfif NOT structKeyExists(application,'inited')>
<cfset application.awscreds = createObject("java","com.amazonaws.auth.BasicAWSCredentials").init(accessKeyId,secretAccessKey)>
<cfset application.sdb = createObject("java","").init(application.awscreds)>
<cfset application.inited = true>
<cfset selectReq = createObject("java","").init("select * from #domainName# where testid = '10000000'")>

The first request took ~ 1500ms but then subsequent requests were about 300ms, which was 1/3 of the time of the raw CF code. With the added benefit of having full access to all the API’s, this is definitely the way we’ll be using it going forward.



This post was posted in , , , , by on