SAWS - S3, SimpleDB, SQS for Scala

Warning: This code is very new, Dec 2009. The only current user is Estful. Consider it buggy and incomplete.

This is a very simple Scala library for working with Amazon's S3, SimpleDB, and SQS.

It really is simple. There are five source files and zero dependencies. Everything is done with the HTTP client in the java.net package. The objects have += and -= and look a bit like Scala collections.

You probably want to start with the examples below and the JavaDoc overview. But don't stop there. The source code is designed to be simple, so you can read it and modify it as you need.

S3 Example

val s3 = new com.zentus.s3.S3(awsKeyId, awsSecretKey)
s3 += "mybucket.example.com"                      // Create a bucket
val mybucket = s3("mybucket.example.com")         // Open a bucket
mybucket += ("myfile", "hello, this is my file")  // Create an entry
val myfile = mybucket("myfile")                   // Get an item reference
Console.println(myfile.mkString)                  // Print file
mybucket -= "myfile"                              // Delete entry

There are extra parameters available for setting mime type and access control. More work is needed providing other header controls, such as cache settings.

SimpleDB Example

val db = new com.zentus.simpledb.SimpleDB(awsKeyId, awsSecretKey)
db += "mydomain"                                  // Create a domain
val dom = db("mydomain")                          // Open a domain
dom += ("myentry", Map(
  "firstname" -> "David",
  "surname"   -> "Crawshaw
))                                                // Create an entry
val entry = mydom("myentry")                      // Get entry (normal Map)
val name = myentry("firstname")                   // Get attribute
val res = db.select("""select * from mydomain
  where firstname='David'""")                     // Run query
Console.println("result: " + res)
dom -= ("myentry", List("firstname", "surname"))  // Remove attributes

Some int/double encoding routines are provided to lexographically order the values for querying. Be careful: they presently have an arbitrary offset value of 100,000 which will might change in the future. That means these interfaces are dangerous and incompatible with other SimpleDB libraries.

SQS Example

Coming soon, the code needs some work.

License

The source is published under the ISC license. Liberal like the BSD license, it too is simple. The entire license sits at the top of each source file. You can't remove the text of the license: that's about the only restriction. If you have any more questions, I suggest reading it.