Last active
December 20, 2017 22:01
-
-
Save matt2000/0d6675c61f5b39b1cbae3e5ed1355b25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
debug = False | |
bucket = 'your-bucket-name' | |
prefix = 'some/s3/prefix/' | |
s3 = boto3.client('s3') | |
size = 0 | |
result = s3.list_objects_v2(Bucket=bucket, Prefix=prefix) | |
try: | |
size += sum([x['Size'] for x in result['Contents']]) | |
except Exception as e: | |
if debug: | |
print(result) | |
raise e | |
while result['IsTruncated']: | |
if debug: | |
print('Continuing from: ' + result['Contents'][0]['Key']) | |
result = s3.list_objects_v2( | |
Bucket=bucket, Prefix=prefix, | |
ContinuationToken=result['NextContinuationToken']) | |
size += sum([x['Size'] for x in result['Contents']]) | |
print('Total size in Gb: ' + str(size / (1000**3))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment