Skip to content

Commit cc63131

Browse files
committed
take into account that S3 bucket may be empty
1 parent aed065a commit cc63131

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

scripts/automated_ingestion/automated_ingestion.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ 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-
files = [
43-
object['Key']
44-
for object in s3.list_objects_v2(Bucket=bucket)['Contents']
45-
]
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'])
47+
4648
tarballs = [
4749
file
4850
for file in files

0 commit comments

Comments
 (0)