S3 allow public directory listing of parent folder?

╄→гoц情女王★ 提交于 2020-07-05 10:03:47

问题


I currently have public permissions for one of my S3 buckets like so:

{
    "Version": "2012-10-17",
    "Id": "Policy1493660686651",
    "Statement": [
        {
            "Sid": "Stmt1493660682556",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::polodata/*"
        }
    ]
}

When a user navigates to a specific file like: https://s3-us-west-2.amazonaws.com/polodata/ETHBTC.csv, it prompts the user to download -- which is fine. However, when they navigate to: https://s3-us-west-2.amazonaws.com/polodata/ (without the file specified), it returns an XML page.

What do I need to change so that the latter returns a directory listing page?


回答1:


You won't get a directory listing page out of Amazon S3 when accessing the URL. The closest is the XML list of objects, for which you must grant ListObjects permission on the bucket policy. It looks like this:

This XML file does not appear to have any style information associated with it. The document tree is shown below.

<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <Name>my-bucket</Name>
  <Prefix/>
  <Marker/>
  <MaxKeys>1000</MaxKeys>
  <IsTruncated>false</IsTruncated>
  <Contents>
    <Key>foo.txt</Key>
    <LastModified>2017-05-01T21:07:13.000Z</LastModified>
    <ETag>"9311482f31be49fb2f41be9e16097a9c"</ETag>
    <Size>213</Size>
    <StorageClass>STANDARD</StorageClass>
  </Contents>
  <Contents>
    <Key>my-folder/</Key>
    <LastModified>2017-05-01T21:07:18.000Z</LastModified>
    <ETag>"d41d8cd98f00b204e9800998ecf8427e"</ETag>
    <Size>0</Size>
    <StorageClass>STANDARD</StorageClass>
  </Contents>
  <Contents>
    <Key>my-folder/bar.txt</Key>
    <LastModified>2017-05-01T21:07:30.000Z</LastModified>
    <ETag>"9311482f31be49fb2f41be9e16097a9c"</ETag>
    <Size>213</Size>
    <StorageClass>STANDARD</StorageClass>
  </Contents>
</ListBucketResult>

Some people have come up with creative ways of simulating a directory listing, eg: Directory Listing in S3 Static Website

Remember -- Amazon S3 isn't a traditional web server. It's an object storage service that can also serve content to the Internet. So, it won't behave exactly the same as a normal web server.

See also: How Do I Configure an S3 Bucket for Static Website Hosting?



来源:https://stackoverflow.com/questions/43724644/s3-allow-public-directory-listing-of-parent-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!