Skip to content

Commit bcadb2a

Browse files
committed
protect list lambda against empty bucket
1 parent fb8e8e8 commit bcadb2a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lambdas/list/handler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def handler(event, context):
3030
images_bucket = get_bucket_name_images()
3131
images = s3.list_objects(Bucket=images_bucket)
3232

33+
if not images.get("Contents"):
34+
print(f"Bucket {images_bucket} is empty")
35+
return []
36+
3337
result = {}
3438
# collect the original images
3539
for obj in images["Contents"]:
@@ -49,7 +53,7 @@ def handler(event, context):
4953
# collect the associated resized images
5054
resized_bucket = get_bucket_name_resized()
5155
images = s3.list_objects(Bucket=resized_bucket)
52-
for obj in images["Contents"]:
56+
for obj in images.get("Contents", []):
5357
if obj["Key"] not in result:
5458
continue
5559
result[obj["Key"]]["Resized"] = {

0 commit comments

Comments
 (0)