I upload my html code to S3 and enable the static website option. It works fine only for /index.html
If I navigate to an html file like products/index.html it works fine, but when I navigate to the folder like products/ it fails with AccessDenied.
What is the problem? It should recognise the index.html from inside the folder
{
"Version": "2012-10-17",
"Id": "__POLICYID__",
"Statement": [
{
"Sid": "__SSID__",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::__MYDOMAIN__/*"
}
]
}
2
Answers
Finally this the solution is a lambda@edge thath replace any path finished with / for path/index.html
https://aws.amazon.com/blogs/compute/implementing-default-directory-indexes-in-amazon-s3-backed-amazon-cloudfront-origins-using-lambdaedge/
The issue lies in how S3 static website hosting handles folder paths and
index.html
files within subdirectories.in order to make S3 recognize index.html for folder paths, you need to configure the Default Root Object or ensure that the website hosting settings handle
index.html
for subdirectories. you can find that UnderStatic Website Hosting
with theProperties
Tab, ensure theIndex Document
is set toindex.html
. This setting tells S3 to serveindex.html
when a folder path is accessed.like that when you navigate to
https://<bucket-name>.s3-website-<region>.amazonaws.com/products/
it should work fine.