39

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Stu Thompson
  • 38,370
  • 19
  • 110
  • 156

7 Answers7

80

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:

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.

bart
  • 14,958
  • 21
  • 75
  • 105
fiatjaf
  • 11,479
  • 5
  • 56
  • 72
  • 2
    Thank you for finally solving my problem! – Jesse Barnum May 11 '15 at 17:11
  • 2
    Thank you! This has plagued me 15 times and I never understood why. – Hairgami_Master Dec 02 '15 at 17:13
  • 2
    You deserve a medal Sir! – Cemal Eker Oct 27 '16 at 11:52
  • First thank you, clearly you managed to specify something AWS failed to. Now the second question: I encountered this while trying to host my static website using CloudFront (due to HTTPS). Now my index.html document works only inside the root folder but in all others I get the the NoSuchKey error. See https://sbarnea.com/contact/ -- if you add index.html it will work, it also works for the root but not for the folders. – sorin Jan 06 '17 at 17:12
  • 1
    It started to work for me too but it took many hours of waiting. – sorin Jan 11 '17 at 13:45
  • These are known as **Website Endpoints** - more good info here: https://stackoverflow.com/a/44297454/165673 – Yarin Jun 01 '17 at 12:16
  • awesome! It really helps – ruucm Oct 23 '19 at 17:27
37

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

Bruno Bronosky
  • 66,273
  • 12
  • 162
  • 149
Alex Jasmin
  • 39,094
  • 7
  • 77
  • 67
4

You can easily solve it by Amazon CloudFront link. At Amazon CloudFront you could modify the root object. You can download manager here: m1.mycloudbuddy.com/downloads.html.

Naszta
  • 7,560
  • 2
  • 33
  • 49
  • Ha, I had totally forgotten about this two-year old question. Yes, CloudFront is much better at content deliver in general from S3. – Stu Thompson Dec 18 '10 at 08:13
3

Yes. using AWS Cloudfront lets you assign a default file.

Amaroom
  • 31
  • 1
3

Since It's been long time, this question being asked, and Amazon S3 changing their Interface. I would like to answer with updated screenshots.

We need to enable 'static web hosting' for S3 to serve as web hosting. - Go to Properties -> click on static web hosting -> Select 'use this bucket to host a website' - Enter the index document (index.html by default), error document and redirection rules, if any. Selecting static web hosting

use-this-bucket-to-host-a-website

As answered in this answer on Stack Overflow, web hosting link would be: http://bucket-name.s3-website-region.amazonaws.com

Abdullah Khawer
  • 4,461
  • 4
  • 29
  • 66
bhar1red
  • 440
  • 3
  • 10
2

I would suggest reading this thread from 2006 (On Amazon web services developers connection). It seems there's no easy solution to this.

yoavf
  • 20,945
  • 9
  • 37
  • 38
0

you can do it using dns webforwards and cloaking. just forward to the complete path of the index.html

www.example.com forwards to http://www.example.com.s3.amazonaws.com and make sure you cloak the output.

nick
  • 1