我有一个装满了上千份文件的桶。我如何搜索水桶?


当前回答

考虑到你在AWS…我认为你会想要使用他们的CloudSearch工具。把你想要搜索的数据放到他们的服务中…让它指向S3密钥。

http://aws.amazon.com/cloudsearch/

其他回答

(至少)有两个不同的用例可以描述为“搜索桶”:

Search for something inside every object stored at the bucket; this assumes a common format for all the objects in that bucket (say, text files), etc etc. For something like this, you're forced to do what Cody Caughlan just answered. The AWS S3 docs has example code showing how to do this with the AWS SDK for Java: Listing Keys Using the AWS SDK for Java (there you'll also find PHP and C# examples). List item Search for something in the object keys contained in that bucket; S3 does have partial support for this, in the form of allowing prefix exact matches + collapsing matches after a delimiter. This is explained in more detail at the AWS S3 Developer Guide. This allows, for example, to implement "folders" through using as object keys something like folder/subfolder/file.txt If you follow this convention, most of the S3 GUIs (such as the AWS Console) will show you a folder view of your bucket.

2018 - 07年现状: 亚马逊有本地sql像搜索csv和json文件!

https://aws.amazon.com/blogs/developer/introducing-support-for-amazon-s3-select-in-the-aws-sdk-for-javascript/

快进到2020年,使用aws-okta作为我们的2fa,下面的命令,尽管迭代这个特定bucket(+270,000)中的所有对象和文件夹非常缓慢,但运行良好。

aws-okta exec dev -- aws s3 ls my-cool-bucket --recursive | grep needle-in-haystax.txt

这不是一个技术性的答案,但我已经构建了一个允许通配符搜索的应用程序:https://bucketsearch.net/

它将异步索引您的bucket,然后允许您搜索结果。

它是免费使用的(捐赠软件)。

另一种选择是在您的web服务器上镜像S3桶并在本地遍历。诀窍在于本地文件是空的,只用作骨架。或者,本地文件可以保存您通常需要从S3获取的有用元数据(例如,文件大小、mimetype、作者、时间戳、uuid)。当您提供下载文件的URL时,在本地搜索,但要提供到S3地址的链接。

本地文件遍历很容易,而且这种用于S3管理的方法与语言无关。本地文件遍历还可以避免维护和查询文件数据库,或者延迟执行一系列远程API调用来验证和获取桶内容。

您可以允许用户通过FTP或HTTP直接将文件上传到您的服务器,然后在非高峰时段通过递归遍历任意大小文件的目录将一批新的和更新的文件传输到Amazon。在完成向Amazon的文件传输后,将web服务器文件替换为同名的空文件。如果一个本地文件有任何文件大小,那么直接提供它,因为它正在等待批量传输。