def _list_bucket(bucket_name, prefix='', accept_key=lambda k: True): client = boto3.client('s3') ctoken = None while True: # list_objects_v2 doesn't like a None value for ContinuationToken # so we don't set it if we don't have one. if ctoken: response = client.list_objects_v2(Bucket=bucket_name, Prefix=prefix, ContinuationToken=ctoken) else: response = client.list_objects_v2(Bucket=bucket_name, Prefix=prefix) try: content = response['Contents'] except KeyError: pass else: for c in content: key = c['Key'] if accept_key(key): yield key ctoken = response.get('NextContinuationToken', None) if not ctoken: break
def _list_bucket(bucket_name, prefix='', accept_key=lambda k: True): client = boto3.client('s3') ctoken = None while True: if ctoken is not None: response = client.list_objects_v2(Bucket=bucket_name, Prefix=prefix, ContinuationToken=ctoken) else: response = client.list_objects_v2(Bucket=bucket_name, Prefix=prefix) try: content = response['Contents'] except KeyError: pass else: for c in content: if accept_key(c): yield c ctoken = response.get('NextContinuationToken', None) if not ctoken: break
def _list_bucket(bucket_name, prefix='', accept_key=lambda k: True): client = boto3.client('s3') ctoken = None while True: # list_objects_v2 doesn't like a None value for ContinuationToken # so we don't set it if we don't have one. if ctoken: response = client.list_objects_v2(Bucket=bucket_name, Prefix=prefix, ContinuationToken=ctoken) else: response = client.list_objects_v2(Bucket=bucket_name, Prefix=prefix) try: content = response['Contents'] except KeyError: pass else: for c in content: key = c['Key'] if accept_key(key): yield key ctoken = response.get('NextContinuationToken', None) if not ctoken: break
def _list_bucket(bucket_name, prefix='', accept_key=lambda k: True): client = boto3.client('s3') ctoken = None while True: response = client.list_objects_v2(Bucket=bucket_name, Prefix=prefix) try: content = response['Contents'] except KeyError: pass else: for c in content: key = c['Key'] if accept_key(key): yield key ctoken = response.get('NextContinuationToken', None) if not ctoken: break
def _list_bucket(bucket_name, prefix='', accept_key=lambda k: True): client = boto3.client('s3') ctoken = None while True: response = client.list_objects_v2(Bucket=bucket_name, Prefix=prefix, **({ 'ContinuationToken': ctoken } if ctoken else {})) try: content = response['Contents'] except KeyError: pass else: for c in content: key = c['Key'] if accept_key(key): yield key ctoken = response.get('NextContinuationToken', None) if not ctoken: break