1

I have a Cloudfront distribution setup in front of an S3 bucket.

My folder structure in this bucket is something like:

index.html
page1
 - index.html
page2
 - index.html

Now if I visit the site through the standard S3 static website endpoint everything works. I start on / and can click on links that refer to /page1/ and everything loads correctly.

But if I access it through the cloudfront distribution then I get access denied for all accesses like /page1/ -> if I manually type in /page1/index.html it works though.

My problem is that my website is statically generated and I cannot change the links to refer to /page1/index.html instead of /page1/

How do I allow these directory level accesses via cloudfront?

Jonathan R
  • 3,652
  • 3
  • 22
  • 40
  • 1
    Did you configure the Origin to point to the Static Website endpoint (eg `MY-BUCKET.s3-website-region.amazonaws.com`) rather than just selecting the bucket itself? This might be useful: [Use CloudFront to serve a static website hosted on Amazon S3](https://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-serve-static-website/) – John Rotenstein Jan 18 '22 at 11:48
  • No I selected the bucket - that was my mistake. Your answer pointed me into the right direction - I found this answer to solve my problem: https://stackoverflow.com/questions/59634922/how-do-i-serve-index-html-in-subfolders-with-s3-cloudfront – Jonathan R Jan 18 '22 at 13:38

1 Answers1

0

You may want to take a look at this. https://aws.amazon.com/blogs/compute/implementing-default-directory-indexes-in-amazon-s3-backed-amazon-cloudfront-origins-using-lambdaedge/.

Using Lambda@Edge, you can dynamically modify requests. For example, appending /index.html.

Register Sole
  • 3,206
  • 1
  • 14
  • 22