Skip to content

zeke/s3-bucket-lister

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

S3 Bucket Lister

A CORS-friendly webservice for fetching S3 bucket contents as JSON(P).

Usage

Here are a few ways to get a file listing for a bucket name "loafer":

Browser:
s3-bucket-lister.herokuapp.com/loafer

Shell:

curl -H "Content-Type: application/json" https://s3-bucket-lister.herokuapp.com/loafer

jQuery:

var bucket = "loafer";
$.getJSON("https://s3-bucket-lister.herokuapp.com/"+bucket, function(files) {
  console.log(files);
});

Patterns

You can use glob expressions to limit the result set to filenames that match a specific pattern:

/mix.joe.sikelianos.com?pattern=songs/*

AWS Credentials

If no AWS credentials are included with your request, then the app's AWS_ACCESS_KEY and AWS_SECRET_KEY environment variables are used to fulfill the request. You can override this default by passing in your own key and secret as query parameters:

/nether-bucket?key=AKIAJRC74QAUTBQQ5BTA&secret=yfk1aVb/s/txkA2atOJH0pmIGnEz4Pv/glqH4SUv

Amazon's Identity and Access Management (IAM) enables you to create multiple users within your AWS account. I recommend creating a user with read-only privileges to your account's buckets.

Development Setup

To run an instance of this service for use with your own AWS account:

cp .env.sample .env # then add your S3 credentials
npm install
foreman start

Then open localhost:5000/some-bucket in your browser, where some-bucket is the name of a bucket on your S3 account. You should see the contents of your bucket in a format like this:

[
  {
    "filename": "app.json",
    "encodedFilename": "app.json",
    "url": "http://loafer.s3.amazonaws.com/app.json"
  },{
    "filename": "index.html",
    "encodedFilename": "index.html",
    "url": "http://loafer.s3.amazonaws.com/index.html"
  }
]

Deploying to Heroku

Assuming you've added your S3 credentials to .env per the development instructions above, then:

heroku create my-bucket-list
git push heroku master
heroku plugins:install git://github.com/ddollar/heroku-config.git
heroku config:push -a my-bucket-list
open https://my-bucket-list.herokuapp.com/some-bucket

License

MIT

About

A CORS-friendly webservice for fetching S3 bucket contents as JSON(P).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published