I’ve got Buckets!

Jan 8, 2008

I have finished the “Hello World!” of connecting to Amazon S3 with LotusScript. I have basically completed a “ListAllMyBuckets” call.

I wish I could post all of my code but I’m still waiting to hear back from Julian Robichaux. I can always try and find him at Lotusphere.

The ListMyBuckets Agent:

Function FormatDateToISO8601(aDate As NotesDateTime) As String
	' Thanks to Joel Litton http://www.joelitton.net/A559B2/home.nsf/d6plinks/JLIN-5UU4B2
	Dim dtLocal As NotesDateTime
	Dim dtGMT As NotesDateTime
	Set dtGMT = New NotesDateTime( Left$(aDate.GMTTime, 22) )
	FormatDateToISO8601= Format$(dtGMT.LSLocalTime, "yyyy-mm-ddThh:nn:ss.000Z")
End Function

Sub Initialize

	Const mysecretkey = PUT YOUR SECRET KEY HERE
	Const myAccessKey = PUT YOUR ACCESS KEY HERE
	Dim myS3 As New AmazonS3_n3()
	Dim mydate As New XSD_DATETIME
	Dim mykey As New XSD_STRING
	Dim mysig As New XSD_STRING

	Dim dateTime As New NotesDateTime( "" )
	Dim hmacbuilder As String
	Dim formattedDate As String
	Call dateTime.SetNow

	Dim mybuckets As ListAllMyBucketsResult_n3
	formattedDate = FormatDateToISO8601(dateTime)
	Call mydate.setValueFromString(formattedDate)
	Call mykey.setValueFromString(myaccesskey)
	HMACBuilder = "AmazonS3ListAllMyBuckets" + formattedDate
	Call mysig.setValueFromString(HMAC_SHA1_B64(mysecretkey,HMACBuilder))
	Set mybuckets =  myS3.ListAllMyBuckets(mykey,mydate,mysig)

End Sub

You basically send Amazon three things in the web service. Your Access Key, the date, and then a signature which is a HMAC_SHA1 encoded concatenation of “AmazonS3″ + the function you’re running + the date.
I had to tweak Joel Litton’s ISO8601 date a bit to add extra zeros for precision.

The hardest code part was the HMAC_SHA1 encoding. I found HMAC code and I found SHA1 but combining the two seemed to be harder than I thought. Paul Johnston’s Javascript code made the most sense to me so I ported a lot of his code to LotusScript. I used a fair chunk of Julian Robichaux’s SHA1 script also (hence the need to get Julian’s permission to post). I spent a lot of time shifting bits and worrying about signed and unsigned operations.

In the end… Amazon likes my scripts because it actually returns something. I am slightly worried about these Web Services in Domino 8. When my scripts were wrong and a fault was returned. I expected the fault codes to populate correctly in the object and they were not. I’m not sure who’s fault that is. We’ll keep experimenting.

What’s next? I want to use Amazon to store files straight from Domino and I would love to load files (images?) from S3 on the fly.

by tom | Categories: lotus, programming, web design |

No Responses so far | Have Your Say!

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>