Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access files stored on Amazon S3 through web browser

Tags:

amazon-s3

Current Situation

I have a project on GitHub that builds after every commit on Travis-CI. After each successful build Travis uploads the artifacts to an S3 bucket. Is there some way for me to easily let anyone access the files in the bucket? I know I could generate a read-only access key, but it'd be easier for the user to access the files through their web browser.

I have website hosting enabled with the root document of "." set.

Screenshot of website hosting setup

However, I still get an 403 Forbidden when trying to go to the bucket's endpoint.

403 Forbidden

The Question

How can I let users easily browse and download artifacts stored on Amazon S3 from their web browser? Preferably without a third-party client.

like image 339
Zach Latta Avatar asked May 28 '13 04:05

Zach Latta


People also ask

Can I access S3 bucket from browser?

In short, if you set x-amz-acl: public-read on a file then you can access it as https://s3.amazonaws.com/bucket-name/path-to-file . No need for enabling website hosting, unless you want the pretty hostname and support for index and error documents.

How do I access my Amazon S3 files?

You can also download the object to your local computer. In the Amazon S3 console, choose your S3 bucket, choose the file that you want to open or download, choose Actions, and then choose Open or Download. If you are downloading an object, specify where you want to save it.

How do I access private S3 bucket in browser?

To see how this works, click a private file in the Amazon S3 Management Console, then choose Open from the Actions menu. The object will be opened. This is done by providing the browser with a pre-signed URL that includes a cryptographically-sized URL and a period of validity.

Can I read S3 file without downloading?

Reading objects without downloading them Similarly, if you want to upload and read small pieces of textual data such as quotes, tweets, or news articles, you can do that using the S3 resource method put(), as demonstrated in the example below (Gist).


1 Answers

I found this related question: Directory Listing in S3 Static Website

As it turns out, if you enable public read for the whole bucket, S3 can serve directory listings. Problem is they are in XML instead of HTML, so not very user-friendly.

There are three ways you could go for generating listings:

  • Generate index.html files for each directory on your own computer, upload them to s3, and update them whenever you add new files to a directory. Very low-tech. Since you're saying you're uploading build files straight from Travis, this may not be that practical since it would require doing extra work there.

  • Use a client-side S3 browser tool.

    • s3-bucket-listing by Rufus Pollock
    • s3-file-list-page by Adam Pritchard
  • Use a server-side browser tool.

    • s3browser (PHP)
    • s3index Scala. Going by the existence of a Procfile, it may be readily deployable to Heroku. Not sure since I don't have any experience with Scala.
like image 90
Myrne Stol Avatar answered Oct 06 '22 15:10

Myrne Stol