Skip to content
Snippets Groups Projects
Commit 3ebc6d5d authored by nimrod's avatar nimrod
Browse files

Fix a bug that botocore doesn't return a `Contents` key when the bucket is

empty.
parent 1091fa7e
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,10 @@ def get_file_list(conn, bucket, prefix=""): ...@@ -31,7 +31,10 @@ def get_file_list(conn, bucket, prefix=""):
# I'm not concerened with the limitation of number of keys in the # I'm not concerened with the limitation of number of keys in the
# response as the buckets have a lifecycle rule enabled and files are # response as the buckets have a lifecycle rule enabled and files are
# automatically moved of the bucket. # automatically moved of the bucket.
files = conn.list_objects_v2(Bucket=bucket, Prefix=prefix)["Contents"] response = conn.list_objects_v2(Bucket=bucket, Prefix=prefix)
if "Contents" not in response:
return []
files = response["Contents"]
files.sort(key=lambda x: x["LastModified"], reverse=True) files.sort(key=lambda x: x["LastModified"], reverse=True)
files = files[:2] files = files[:2]
for file in files: for file in files:
...@@ -96,7 +99,7 @@ def main(): ...@@ -96,7 +99,7 @@ def main():
exit(3) exit(3)
if not files: if not files:
print("Not matching files in bucket.") print("No matching files in bucket.")
exit(2) exit(2)
# Calculate the age of the latest file and if it's in the thresholds set. # Calculate the age of the latest file and if it's in the thresholds set.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment