- Newest
- Most votes
- Most comments
It's a best practice to point the root URL of the CloudFront distribution to a specific file in your origin (like the S3 bucket) to avoid just the exposure you're seeing. The procedure is explained in this documentation article: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/DefaultRootObject.html
you can try using Lambda @ Edge. You can effectively route requests to specific domain or URL. Below is the blog not related to problem you are trying to solve, but it gives you direction on how to accomplish rerouting.
I'm pleased you found a solution that works, but the behavior you were experiencing shouldn't be happening. To get the XML listing the contents of the bucket, the ListBucket permission must be granted somewhere. CloudFront should return a 403 when a viewer requests the root if there is no ListBucket permission. Is the policy snippet you included above the entire policy? Does the bucket also have any sort of public access enabled? Or are you also using a Bucket ACL?
Even though you have a working solution, it would be worth double-checking the S3 security configuration to make sure there isn't any unintended access.
Relevant content
- asked 3 years ago

Thanks! This works. We opted to point the URL to a file that does not exist which gives us NoSuchKey for the root path.