Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to have index.html functionality with content hosted on S3?

Is there a way to make S3 default to an index.html page? E.g.: My bucket object listing:

/index.html /favicon.ico /images/logo.gif 

A call to www.example.com/index.html works great! But if one were to call www.example.com/ we'd either get a 403 or a REST object listing XML document depending on how bucket-level ACL was configured.

So, the question: Is there a way to have index.html functionality with content hosted on S3?

like image 522
Stu Thompson Avatar asked Aug 26 '08 12:08

Stu Thompson


People also ask

Does S3 have indexing?

The heart of the S3 object index is a DynamoDB table with one item per object, which associates various attributes with the object's S3 key. Each item contains the S3 key, the size of the object, and any additional attributes to use for lookups.

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.

Can we use S3 for dynamic website?

Amazon S3 does not support server-side scripting, but AWS has other resources for hosting dynamic websites. To learn more about website hosting on AWS, see Web Hosting . You can use the AWS Amplify Console to host a single-page web app.


2 Answers

For people still struggling against this after 3 years, let me add some important information:

The URL for your website (and to which you have to point your DNS) is not

<bucket_name>.s3-us-west-2.amazonaws.com, but

<bucket_name>.s3-website-us-west-2.amazonaws.com.

If you use the first, it will not work as intended, no matter how much you config the Index document.

For a specific example, consider:

  • http://www-example-com.s3.amazonaws.com/index.html works.
  • http://www-example-com.s3.amazonaws.com/ fails with AccessDenied.
  • http://www-example-com.s3-website-us-west-2.amazonaws.com/ works!

To get your true website address, go to your S3 Management Console, select the target bucket, then Properties, then Static Website Hosting. It will show the website URL that will work.

like image 144
fiatjaf Avatar answered Sep 21 '22 17:09

fiatjaf


Amazon S3 now supports Index Documents

The index document for a bucket can be set to something like index.html. When accessing the root of the site or a sub-directory containing a document of that name that document is returned.

It is extremely easy to do using the aws cli:

aws s3 website $MY_BUCKET_NAME --index-document index.html 

You can set the index document from the AWS Management Console:

enter image description here

like image 31
Alex Jasmin Avatar answered Sep 22 '22 17:09

Alex Jasmin