aws icon indicating copy to clipboard operation
aws copied to clipboard

Programatically set S3 Bucket Website IndexDocument

Open rjocoleman opened this issue 12 years ago • 6 comments

Is there any way to set IndexDocument for S3 buckets?

http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTwebsite.html

rjocoleman avatar Feb 11 '13 08:02 rjocoleman

I just added support for ?website, so please download the latest version from github.

Here is an example:

echo '<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><RedirectAllRequestsTo><HostName>timkay.com</HostName></RedirectAllRequestsTo></WebsiteConfiguration>' |aws put s3.timkay.com?website

timkay avatar Feb 13 '13 20:02 timkay

Thanks @timkay!

I'm not able to get this to work however as expected, is there some way to see verbose output? I'm getting no output from the command, no errors and the expected change is not made.

echo '<?xml version="1.0" encoding="UTF-8"?>
<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
</WebsiteConfiguration>' | aws put my-s3-bucket?website

rjocoleman avatar Feb 14 '13 06:02 rjocoleman

You can add -v or -vv (two v's) to see the actual request sent to S3. I don't think any output is expected from S3... Simply this meta document is written. You can confirm the command worked using "aws get ...?website" :+1:

$ aws get s3.timkay.com?website
<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
        <RedirectAllRequestsTo>
                <HostName>timkay.com</HostName>
        </RedirectAllRequestsTo>
</WebsiteConfiguration>

It working or not is beyond the scope of the "aws" command. At this point, it's a question entirely about S3 behavior.

timkay avatar Feb 14 '13 06:02 timkay

Thanks Tim,

It's "working" and I can see AWS reporting the correct details when I aws get ...?website.

My issue was in my web browser I was accessing http://my-s3-bucket.s3.amazonaws.com/ and, per the docs, it should have been http://my-s3-bucket.s3-website-us-east-1.amazonaws.com/

rjocoleman avatar Feb 14 '13 10:02 rjocoleman

As I understand it, S3 will redirect from the first URL to the second, so either should work. However, it takes some propagation time after creation of the bucket, so the redirection doesn't work immediately. I might be wrong. Please point me to the relevant documentation.

timkay avatar Feb 14 '13 14:02 timkay

The trailing slash at the root-level URL is optional. For example, if you configure your website with index.html as the index document, either of the following two URLs will return index.html.

http://example-bucket.s3-website-region.amazonaws.com/ http://example-bucket.s3-website-region.amazonaws.com

http://docs.aws.amazon.com/AmazonS3/latest/dev/IndexDocumentSupport.html

I know this isn't strictly the question being answered above, the best I can see in the docs at this point is there thought. When setting up Static Website Hosting through the console it specifies the Endpoint.

staticwebsitehosting10

rjocoleman avatar Feb 14 '13 20:02 rjocoleman