2
votes

I have an S3 website configured to be used as a static website, and a Cloudfront distribution with the S3 bucket as the origin.

My index files are called index and I have specified this as the index files in both the bucket configuration and the Cloudfront distribution configuration.

enter image description here

enter image description here

However if I go to https://example.com/directory/ I get an error document as follows, where the RequestID and HostID change on each request:

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>7F09A18821FE70FD</RequestId><HostId>H5OR+AZpNSGlhrUX1ECegTbWkio728A1MIdGkO4bkCZIJa/XQ6Uv7Hu0GgNgyxL+snerPPDnzr8=</HostId></Error>

If I go to https://example.com/directory/index then the page shows correctly.

If I access the website from either the cloudfront URL or the S3 website endpoint, rather than my custom domain, then the problem does not happen.

How can I get the directory index pages to be served correctly when accessing the S3 bucket?

1
Add .html to the document name. - hephalump
s3 website hosting serve only .html content. U can server as example.com/directory/index/ but inside index/index.html folder has to present for other folder. - aviboy2006
@aviboy2006 S3 can serve whatever file names you want, with whatever MIME types you want. - Mark Fisher
Agree. Try this stackoverflow.com/questions/50299204/… this setting - aviboy2006
Please provide the entire error response, not just "Access Denied." - Michael - sqlbot

1 Answers

2
votes

Changing the origin for the distribution from <bucket-name>.s3.amazonaws.com to <bucket-name>.s3-website.eu-west-2.amazonaws.com fixed the issue.

Unfortunately when I started typing in the dropdown in the Origin settings, Amazon started to suggest S3 buckets, and it suggested the bucket using the first format.