Search code examples
amazon-web-servicesrandombucket

How to read random objects from a bucket with java?


I want to read random objects from a bucket . i do not want to store keys and pick with randomly a key and get the object because i think it is an expensive operation . thanks


Solution

  • S3 cannot "randomly" pick objects for you to read.

    In order to read data for an object, you must know it's key.

    In order to know it's key, you must do one of the following:

    • Use another data store to hold the keys (such as database, DynamoDB, flat file, etc.), or
    • Enumerate the objects first, then pick from what was found.

    You initially rejected the storage of keys because you think the operation is expensive. However, based on the possible solutions, it's probably the least expensive.