diff --git a/check_s3_bucket/__init__.py b/check_s3_bucket/__init__.py index 49214618fed5ace7894228862c21eecbde5c764f..751d640cbf4bf3374a0f595cfcc7ddd83225f4f9 100755 --- a/check_s3_bucket/__init__.py +++ b/check_s3_bucket/__init__.py @@ -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.