8/27/2021

AWS, find all file list in s3 bucket

 Find all file list in s3 bucket

import boto3
BUCKET_INPUT = 'bucket_name'
PREFIX_INPUT = 'some_prefix_folder_name'
item_list_all = []
paginator = s3_client.get_paginator('list_objects')
operation_parameters = {'Bucket': BUCKET_INPUT} #,'Prefix': PREFIX_INPUT}
page_iterator = paginator.paginate(**operation_parameters)
for page in page_iterator:
item_list_all.append(page['Contents'])
key_all = []
for page in item_list_all:
for i in range(len(page)):
key_all.append(page[i]["Key"])
print("The total number of files in the bucket:", len(key_all) )

Thank you.

www.marearts.com


No comments:

Post a Comment