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

7

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?

Robbynrobe answered 26/8, 2008 at 12:30 Comment(0)
B
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

Barbarian answered 18/2, 2011 at 10:22 Comment(4)
Yeah. I posted this as soon as I heard the announcement.Barbarian
PS: Love the freehand circles ;)Robbynrobe
unfortunately this works when it feels like it. I have this configures on one bucket that works great, and another bucket, won't work, still list the XML bullshit.Farceuse
See the answer by fiatjaf to get the rest of the story. Just setting the Index Document is not enough. You have to be using a modified domain name as well.Cardin
S
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.

Socinian answered 24/6, 2014 at 3:17 Comment(7)
Thank you for finally solving my problem!Tollefson
Thank you! This has plagued me 15 times and I never understood why.Axis
You deserve a medal Sir!Discountenance
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 sbarnea.com/contact -- if you add index.html it will work, it also works for the root but not for the folders.Limestone
It started to work for me too but it took many hours of waiting.Limestone
These are known as Website Endpoints - more good info here: https://mcmap.net/q/18593/-setting-index-document-on-s3-website-with-custom-domainRift
awesome! It really helpsZetta
B
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

Barbarian answered 18/2, 2011 at 10:22 Comment(4)
Yeah. I posted this as soon as I heard the announcement.Barbarian
PS: Love the freehand circles ;)Robbynrobe
unfortunately this works when it feels like it. I have this configures on one bucket that works great, and another bucket, won't work, still list the XML bullshit.Farceuse
See the answer by fiatjaf to get the rest of the story. Just setting the Index Document is not enough. You have to be using a modified domain name as well.Cardin
B
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.

Biophysics answered 17/12, 2010 at 21:30 Comment(1)
Ha, I had totally forgotten about this two-year old question. Yes, CloudFront is much better at content deliver in general from S3.Robbynrobe
P
3

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

Platon answered 9/8, 2010 at 1:8 Comment(0)
T
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

Tartarus answered 15/6, 2017 at 18:5 Comment(0)
I
2

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

Influent answered 26/8, 2008 at 12:47 Comment(0)
V
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.

Vulnerary answered 21/5, 2010 at 6:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.