简体   繁体   中英

download all files from s3 bucket including paging python

I am trying to download all my files from a s3 bucket this is the code I have:

s3 = boto3.client('s3',
                  aws_access_key_id=ACCESS_KEY,
                  aws_secret_access_key=SECRET_KEY
                  )
key_list = s3.list_objects(Bucket=bucket_name)['Contents']
for key in key_list:
    s3.download_file(bucket_name, key['Key'], key['Key'])

but it downloads only the 1st page files... how can I download all the files from all the pages?

The code below create a list of all bucket objects.

  s3 = boto3.resource('s3')
  bucket = s3.Bucket(bucket_name)
  return [o.key for o in bucket.objects.all()]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM