How to get more than 1000 objects from S3 by using list_objects_v2?

后端 未结 3 1923
挽巷
挽巷 2021-01-01 09:55

I have more than 500,000 objects on s3. I am trying get the size of each object. I am using the following python code for that

3条回答
  •  鱼传尺愫
    2021-01-01 10:28

    If you don't NEED to use the boto3.client you can use boto3.resource to get a complete list of your files:

    s3r = boto3.resource('s3')
    bucket = s3r.Bucket('bucket_name')
    files_in_bucket = list(bucket.objects.all())
    

    Then to get the size just:

    sizes = [f.size for f in files_in_bucket]
    

    Depending on the size of your bucket this might take a minute.

提交回复
热议问题