s3tree

Hierarchical object listing on S3

npm install s3tree
2 downloads in the last week
8 downloads in the last month

s3tree

Hierarchical object listing on S3.

dependency status

Example

Given the following objects on S3:

2012/12/24/23-12-09.jpg
2013/02/31/14-00-04.jpg
2013/09/05/20-45-10.jpg
2013/09/05/20-45-12.jpg
2013/09/06/21-03-42.jpg
2013/10/25/09-51-33.jpg

s3tree can list the hierarcy with:

var tree = require('s3tree')({
  key: process.env.AWS_ACCESS_KEY,
  secret: process.env.AWS_SECRET_KEY,
  region: process.env.AWS_REGION,
  bucket: process.env.S3_BUCKET
});

tree('', function (err, years) {
  years.forEach(function (year) {
    tree(year, function (err, months) {
      console.log(months.join(' '));
    });
  });
});

which will output:

2012/12/
2013/02/ 2013/09/ 2013/10/

With the hierarcy mapped it's easy to stream all object keys of a given year, month, or day with s3ls.

Methods

var s3tree = require('s3ls')(opts);

The following opts must be passed in:

  • opts.key - AWS access key ID.
  • opts.secret - AWS secret access key.
  • opts.region - AWS geographic region.
  • opts.bucket - Existing S3 bucket for uploads.

s3tree(prefix, cb(err, prefixes) {})

Provide a callback which will be called with an error err or the prefixes under the given prefix.

License

MIT

npm loves you