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
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -31,7 +31,10 @@ def get_file_list(conn, bucket, prefix=""):
    # 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
    # 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 = files[:2]
    for file in files:
@@ -96,7 +99,7 @@ def main():
        exit(3)

    if not files:
        print("Not matching files in bucket.")
        print("No matching files in bucket.")
        exit(2)

    # Calculate the age of the latest file and if it's in the thresholds set.