0
votes

I'm trying to get all objects including different versions of the same object as well. According to aws official documents, it has Prefix and KeyMarker. I can't see any special difference between them. It says both like below,

  • KeyMarker — (String) Specifies the key to start with when listing objects in a bucket.
  • Prefix — (String) Use this parameter to select only those keys that begin with the specified prefix. You can use prefixes to separate a bucket into different groupings of keys. (You can think of using prefix to make groups in the same way you'd use a folder in a file system.) You can use prefix with delimiter to roll up numerous objects into a single result under CommonPrefixes.

I'd like you to take an example to get to know it if possible. Thanks.

FYI) I took an example like my bucket name is example and my file is located in app/a.json in the bucket. In that case, it can call listObjectVersions with the param: { Bucket: "example", "Prefix": "app/a.json" } but doesn't work with { Bucket: "example", "KeyMarker": "app/a.json" }

1

1 Answers

1
votes

There is a pretty big difference between the both of these, although I can see how it can be easy to get confused with the terminology.

Prefix

This is used for requests to limit objects based on a start pattern, all S3 "filepaths" are actually the entire key.

So if you wanted to retrieve everything that on a file based system exists in the docs folder in the root of the system, in S3 you would reference the prefix of docs/* to get all objects with a key starting with docs/.

KeyMarker

This can be used in conjunction or independently to prefix, it comes down to when your list objects request returns too many objects to list, it becomes paginated returning you both the objects and a property named NextKeyMarker.

You would use this property to perform the same request again but this time adding the value of the NextKeyMarker as your KeyMarker. This would essentially return you the next page starting with the key you have specified.