Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directory Listing in S3 Static Website

I have set up an S3 bucket to host static files.

When using the website endpoint (http://.s3-website-us-east-1.amazonaws.com/): it forces me to set an index file. When the file isn't found, it throws an error instead of listing directory contents.

When using the s3 endpoint (.s3.amazonaws.com): I get an XML listing of the files, but I need an HTML listing that users can click the link to the file.

I have tried setting the permissions of all files and the bucket itself to "List" for "Everyone" in the AWS Console, but still no luck.

I have also tried some of the javascript alternatives, but they either don't work under the website url (that redirects to the index file) or just don't work at all. As a last resort, a collapsible javascript listing would be better than nothing, but I haven't found a good one.

Is this possible? If so, do I need to change permissions, ACL or something else?

like image 507
iJeep Avatar asked Feb 12 '12 22:02

iJeep


People also ask

Can Amazon S3 run a static website?

After you create a bucket, you can enable static website hosting for your bucket. You can create a new bucket or use an existing bucket. Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ .

Are there directories in S3?

Directories don't actually exist within S3 buckets. The entire file structure is actually just one flat single-level container of files. The illusion of directories are actually created based on naming the files names like dirA/dirB/file .

What is static website in S3?

You can use Amazon S3 to host a static website. On a static website, individual webpages include static content. They might also contain client-side scripts. By contrast, a dynamic website relies on server-side processing, including server-side scripts, such as PHP, JSP, or ASP.NET.

What is the index document file in an S3 hosted website?

An index document is a webpage that Amazon S3 returns when a request is made to the root of a website or any subfolder. For example, if a user enters http://www.example.com in the browser, the user is not requesting any specific page.


2 Answers

I've created a simple bit of JS that creates a directory index in HTML style that you are looking for: https://github.com/rgrp/s3-bucket-listing

The README has specific instructions for handling Amazon S3 "website" buckets: https://github.com/rgrp/s3-bucket-listing#website-buckets

You can see a live example of the script in action on this s3 bucket (in website mode): http://data.openspending.org/

enter image description here

like image 70
Rufus Pollock Avatar answered Sep 30 '22 18:09

Rufus Pollock


There is also this solution: https://github.com/caussourd/aws-s3-bucket-listing

Similar to https://github.com/rgrp/s3-bucket-listing but I couldn't make it work with Internet Explorer. So https://github.com/caussourd/aws-s3-bucket-listing works with IE and also add the possibility to order the files by names, size and date. On the downside, it doesn't follow folders: only the files at one level are displayed.

like image 44
Céline Aussourd Avatar answered Sep 30 '22 17:09

Céline Aussourd