I need to get the last file of a bucket and I searched in the documentation but I could not find any way of getting the list of objects in a bucket in descending alphabetical order.
Is there a way to do it using boto3?
Thank you for your help
@yannbriancon - Thank you for your post. You can use python's sorted function to sort the keys in descending order. Here is a code sample:
import boto3
s3 = boto3.client('s3')
res = s3.list_objects(Bucket='bucketname')
output = sorted(res['Contents'],key=lambda i:i['Key'],reverse=True)
print(output)
Hope it helps.
@swetashre How would you handle a key list longer than 1000 objects?
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.
Most helpful comment
@swetashre How would you handle a key list longer than 1000 objects?