I was looking to discover all available prefixes at https://commondatastorage.googleapis.com/chromium-browser-snapshots, but I can’t seem to find documentation on listing AWS S3 prefixes. I found plenty of documentation on how to list all bucketitems given a prefix, but not how to list all prefixes.
I found documentation on an LS command, but I have no idea what the intended use is. I think it is for some kind of AWS management console. I am more looking for a RESTful API that I can implement as an XHR request in JavaScript or PowerShell.
I believe that storage API is the bucket for all Chromium builds ever built by the chromium developer team. According to the response from that URL, it uses the AWS S3 API.
Google’s cloud storage API also seems to hint at the fact that it uses AWS’s S3 API.
2
Answers
When you list the contents of a bucket using
ListObjects()
and pass aDelimiter
, S3 will return a list ofCommonPrefixes
:This will show a list of all Prefixes before the first
/
.If you want to list ALL prefixes in the bucket (without recursively going through each prefix and making the above call), the easiest method is to retrieve all objects keys and then just remove everything after the last slash in an object key.
Something like:
The core the of the REST API that S3 and S3 compatible systems use is documented by AWS.
For the case of getting prefixes, you can call it with a call like:
Which returns an XML document like:
There may be one more more
CommonPrefixes/Prefix
nodes with the common prefixes. And there may be one moreContents/Key
items with the objects that do not share a common prefix. If theIsTruncated
node is set totrue
, then you will need to perform another request with the contents ofNextMarker
as themarker
value:Note that you can’t simply blindly pass the value from NextMarker and use it in the URL, you will need to decode it’s value, either with a library, or manually parsing it out to ensure that you decode any XML entities, and then encode the value use standard URL encoding rules.
Finally, this ignores the rules for performing signed requests. For open buckets like this one in the question, this doesn’t matter, but for most S3 buckets, you will need to follow the documentation to sign a request.