2

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?

8
  • 1
    Add .html to the document name. Commented Dec 23, 2019 at 0:14
  • 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. Commented Dec 23, 2019 at 4:46
  • 1
    @aviboy2006 S3 can serve whatever file names you want, with whatever MIME types you want. Commented Dec 23, 2019 at 9:41
  • Agree. Try this stackoverflow.com/questions/50299204/… this setting Commented Dec 23, 2019 at 9:44
  • Please provide the entire error response, not just "Access Denied." Commented Dec 23, 2019 at 11:38

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.