简体   繁体   English

如何从公共Amazon s3存储桶中列出内容

[英]How to list content from a public Amazon s3 bucket

I have configured my bucket to be public, which means everyone can view the bucket as: http://bucket.s3-website-us-east-1.amazonaws.com/ 我已将存储桶配置为公开存储,这意味着每个人都可以通过以下方式查看存储桶: http : //bucket.s3-website-us-east-1.amazonaws.com/

Now I need to be able to get the list of objects and download it if required. 现在,我需要能够获取对象列表并根据需要下载它。

I found answers on this very helpful in getting me setup on python: Quick way to list all files in Amazon S3 bucket? 我发现有关此问题的答案非常有助于我在python上进行设置: 列出Amazon S3存储桶中所有文件的快速方法?

This work fine if I input the access-key and secret-access-key. 如果我输入访问密钥和秘密访问密钥,则可以正常工作。

The problem though is we might have people accessing the bucket who we don't want to have any keys at all. 但是问题是,我们可能会有人根本不想拥有任何钥匙,而正在访问存储桶。 So if the keys are not provided it gives me 400 Bad Response error. 因此,如果未提供密钥,则会给我400错误响应错误。

At first I thought this might be impossible. 起初,我认为这可能是不可能的。 But extensive search led me to this R-package: Cloudyr R package 但是广泛的搜索使我找到了这个R-package: Cloudyr R包

Using this I am able to full the objects without need of the keys: 使用此工具,我无需键即可填充对象:

get_bucket(bucket = 'bucket')

in R but the functionalities are limited in listing/downloading the files. 在R中,但功能仅限于列出/下载文件。 Any ideas how I go about doing this in boto? 有什么想法我该如何在Boto中做到这一点?

The default S3 policy is all deny ,so you need to set permission policy to it 默认的S3策略为all deny,因此您需要为其设置权限策略

  • choose your bucket and click property 选择您的存储桶并单击属性
  • add more permissions grantee everyone can list 添加更多许可权,所有人可以列出
  • edit bucket policy get object 编辑存储桶策略获取对象

I think what you need is Bucket Policy which will allow for anonymous to read objects stored. 我认为您需要的是存储桶策略,该策略将允许匿名读取存储的对象。

Granting Read-Only Permission to an Anonymous User should help. 向匿名用户授予只读权限应该会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM