0

I have a long list of keys I want to check for existence in s3. They have different prefixes, and I want this to be fast, thus checking one by one won't do the trick.

This checks one by one
This assumes similar prefixes.

I need a call similar to the following

def keys_that_exist(keys: Sequence[str]) -> Sequence[bool]:
    return [True if i % 2 == 0 else False for i, key in enumerate(keys)] # just some example output.

How to do this without an API call to s3 for each and every key, using boto3 or another Python library?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Gulzar
  • 23,452
  • 27
  • 113
  • 201
  • Pretty much the only option is something like your second solution, just listing all of the objects in the bucket instead under a targeted prefix. – Anon Coward Mar 16 '23 at 16:17
  • Agreed. There are no other options. Either `head_object()` each object, or list the relevant Prefix in the bucket and examine the response. – John Rotenstein Mar 16 '23 at 21:14

0 Answers0