Skip to content

learning how to use S3Ajax to access Amazon S3

In a previous post ( Amazon S3 signature calculation in JavaScript), I show how to calculate using JavaScript a "signature" need to access Amazon S3. In this post, I show a code snippet for using Leslie Michael Orchard's S3Ajax, which I'm evaluating for using to connect Zotero with Amazon S3. (Like the code from my previous calculation, it too depends on the sha1.js library.). Here's a Chickenfoot script (which is a slight rewriting of a L. M. Orchard's listbuckets function in play.js) to list your S3 buckets (you need to substitute the appropriate key/secret and download S3Ajax.js and sha1.js and substitute the correct path for these libraries):

include("D:\\document\\JavaScriptLib\\sha1.js");
include("D:\\document\\JavaScriptLib\\S3Ajax.js");

var AWSAccessKeyId = "[AWSAccessKeyId]";
var AWSSecretAccessKey = "[AWSSecretAccessKey]";

S3Ajax.DEBUG = true;
S3Ajax.KEY_ID = AWSAccessKeyId;
S3Ajax.SECRET_KEY = AWSSecretAccessKey;

S3Ajax.listBuckets(
    function(req, obj) {
        if (obj.ListAllMyBucketsResult) {
            var buckets = obj.ListAllMyBucketsResult.Buckets.Bucket;
            for (var i=0, bucket; bucket=buckets[i]; i++) {
                output (
                    bucket.Name + ' ['+bucket.CreationDate+']'
                );
            }
        }
    },
    function(req) {
        output ("Buckets list failed at "+(new Date()));
    }
);

I will have to try some more sophisticated actions — but the simple listing of buckets worked for me.

{ 1 } Trackback

  1. Mashup Guide :: listing keys with S3Ajax | December 17, 2008 at 8:03 am | Permalink

    […] a previous post (learning how to use S3Ajax to access Amazon S3), I show how to use Chickenfoot and S3Ajax to list S3 buckets. Here is a slight elaboration of the […]

Post a Comment

You must be logged in to post a comment.