Title: AWS S3 AccessDenied on subfolder
Tags: amazon-web-services;amazon-s3
Question: 
I have created S3 bucket, and done the steps to enable static web hosting on it.
I have verified it works by going to the URL 
which looks something as following ```https://my-bucket.s3.aws.com```
I want to put my web assets in a sub folder now
I put the web assets in a folder I called ```foobar```
Now if want to access it I have to explictly enter URL as following:
```https://my-bucket.s3.aws.com/foobar/index.html```

So my question is, do I need to use some other service such as CloudFront to enable so I can go into the bucket with the following URL instead ```https://my-bucket.s3.aws.com/foobar```, that is I don't want to have to explicit say ```index.html``` at the end?

Comment: Have you turned on the [S3 bucket static website hosting](https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteHosting.html)?

Comment: Sorry, I missed that point. Why not try the website endpoint? https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteEndpoints.html

Comment: try s3 redirection rules, https://docs.aws.amazon.com/AmazonS3/latest/userguide/how-to-page-redirect.html

Comment: @jellycsc I wrote on the first bullet I have, and the second bullet I've written I've verified it works. Now I want it to work in a `subfolder` :)

Comment: @jellycsc thanks I checked the page, and the endpoint examples on that page. It seems like by using S3 only I need to say the object name too when entering an URL. Whereas I'm looking for a way that it will redirect to `index.html` file when I go to a subfolder without explicitly having it in the URL.


Here is another answer: You can't do this with a default document for a subfolder using CloudFront.  Documentation says
```
However, if you define a default root object, an end-user request for
a subdirectory of your distribution does not return the default root
object. For example, suppose index.html is your default root object
and that CloudFront receives an end-user request for the install
directory under your CloudFront distribution:
http://d111111abcdef8.cloudfront.net/install/
CloudFront does not return the default root object even if a copy of
index.html appears in the install directory.
```
But that same page also says
```
The behavior of CloudFront default root objects is different from the
behavior of Amazon S3 index documents. When you configure an Amazon S3
bucket as a website and specify the index document, Amazon S3 returns
the index document even if a user requests a subdirectory in the
bucket. (A copy of the index document must appear in every
subdirectory.) For more information about configuring Amazon S3
buckets as websites and about index documents, see the Hosting
Websites on Amazon S3 chapter in the Amazon Simple Storage Service
Developer Guide.
```
So check out out that referenced guide, and the section on Configuring an Index Document in particular.

Comment for this answer: What if your s3 bucket isn't configured as website?! I don't have a root object (since that's all I read on SO as a suggestion). I can access objects within the root of the bucket, but can't for "subfolders".

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 5, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:04/15/21', 'FavoriteCount': 2.0, 'PostTypeId': 1, 'Tags': '<amazon-web-services><amazon-s3>', 'Title': 'AWS S3 AccessDenied on subfolder', 'ViewCount': 883, 'id': 67111950, 'user_AboutMe': '', 'user_AccountId': 199983.0, 'user_DisplayName': 'starcorn', 'user_Reputation': 7853.0, 'user_Views': 766.0, 'user_id': 445600.0}}