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.
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?