I am trying to replicate the command aws s3 ls s3://bucket/prefix/
using boto3. Currently, I am able to grab all the objects within the path using
s3 = boto3.client('s3')
bucket = "my-bucket"
prefix = "my-prefix"
paginator = s3.get_paginator('list_objects_v2')
page_iterator = paginator.paginate(Bucket=bucket, Prefix = prefix)
Then, I can iterate through page_iterator and manually reconstruct the top-level directories within that path. However, since there are a ton of objects inside the path, retrieving all the objects to reconstruct the results of this command takes roughly 30 seconds for me, whereas the AWS CLI command is pretty much instant. Is there a more efficient way to do this?