Skip to content

Instantly share code, notes, and snippets.

@seventhskye
Created September 15, 2016 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seventhskye/81b2d21347c852d67ffbf39c001b67dd to your computer and use it in GitHub Desktop.
Save seventhskye/81b2d21347c852d67ffbf39c001b67dd to your computer and use it in GitHub Desktop.
A script to loop through a list of bucket objects that would exceed the max-keys.
#!/usr/bin/env python
import boto3
client = boto3.client('s3')
bucket = 'you-s3-bucket'
prefix = 'a-prefix'
NextContinuationToken = True
while NextContinuationToken:
if NextContinuationToken == True:
response = client.list_objects_v2(Bucket=bucket,Prefix=prefix)
else:
response = client.list_objects_v2(Bucket=bucket,Prefix=prefix,ContinuationToken=NextContinuationToken)
NextContinuationToken = response['NextContinuationToken']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment