Skip to content

Instantly share code, notes, and snippets.

@nberserk
Last active January 31, 2024 11:02
Show Gist options
  • Save nberserk/7723597ca73526e1c25c to your computer and use it in GitHub Desktop.
Save nberserk/7723597ca73526e1c25c to your computer and use it in GitHub Desktop.
calculating S3 file size containing <your_filter> in <your_bucket> using boto3 python library.
import boto3
s3 = boto3.resource('s3')
bucket = s3.Bucket('<your_bucket>')
size = 0
for o in bucket.objects.all():
if '<your_filter>' in o.key:
print o, o.size
size += o.size
print 's3 size = %.3f GB' % (size/1024/1024/1024)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment