Skip to content

Commit ddef0c7

Browse files
committed
cleaner approach to dealing with empty S3 bucket
1 parent cc63131 commit ddef0c7

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

scripts/automated_ingestion/automated_ingestion.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ def error(msg, code=1):
3939
def find_tarballs(s3, bucket, extension='.tar.gz', metadata_extension='.meta.txt'):
4040
"""Return a list of all tarballs in an S3 bucket that have a metadata file with the given extension (and same filename)."""
4141
# TODO: list_objects_v2 only returns up to 1000 objects
42-
s3_objects = s3.list_objects_v2(Bucket=bucket)
43-
files = []
44-
# take into account that S3 bucket may be empty (=> no 'Contents' key)
45-
if 'Contents' in s3_objects:
46-
files.extend(obj['Key'] for obj in s3_objects['Contents'])
42+
s3_objects = s3.list_objects_v2(Bucket=bucket).get('Contents', [])
43+
files = [obj['Key'] for obj in s3_objects]
4744

4845
tarballs = [
4946
file

0 commit comments

Comments
 (0)