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


当前回答

在S3控制台中按前缀搜索

直接在AWS Console桶视图中。

使用s3-dist-cp复制需要的文件

当您有数千或数百万个文件时,另一种获取所需文件的方法是使用分布式复制将它们复制到另一个位置。您可以在Hadoop作业中的EMR上运行此操作。AWS很酷的一点是,他们提供了自定义S3版本S3 -dist-cp。它允许您在groupBy字段中使用正则表达式对需要的文件进行分组。例如,您可以在EMR的自定义步骤中使用它

[
    {
        "ActionOnFailure": "CONTINUE",
        "Args": [
            "s3-dist-cp",
            "--s3Endpoint=s3.amazonaws.com",
            "--src=s3://mybucket/",
            "--dest=s3://mytarget-bucket/",
            "--groupBy=MY_PATTERN",
            "--targetSize=1000"
        ],
        "Jar": "command-runner.jar",
        "Name": "S3DistCp Step Aggregate Results",
        "Type": "CUSTOM_JAR"
    }
]

其他回答

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

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/

这是一个有点旧的话题——但也许可以帮助那些仍然在搜索的人——我就是那个搜索了一年的人。

解决方案可能是“AWS Athena”,您可以像这样搜索数据

'SELECT user_name FROM S3Object WHERE cast(age as int) > 20'

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

目前1TB数据的价格是5美元——所以举例来说,如果你的查询搜索超过一个1TB文件的3倍你的成本是15美元——但举例来说,如果你想要读取的只有1列“转换柱状格式”,你将支付价格的1/3,即1.67美元/TB。

下面是一个使用AWS CLI搜索文件名的简短而丑陋的方法:

aws s3 ls s3://your-bucket --recursive | grep your-search | cut -c 32-

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

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