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.
Post a Comment