Programatically set S3 Bucket Website IndexDocument
Is there any way to set IndexDocument for S3 buckets?
http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTwebsite.html
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
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
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.
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/
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.
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.
