diff --git a/aws/cloudwatch-log-costs.py b/aws/cloudwatch-log-costs.py old mode 100755 new mode 100644 index aa6e3f1..f46ab92 --- a/aws/cloudwatch-log-costs.py +++ b/aws/cloudwatch-log-costs.py @@ -23,6 +23,8 @@ queries = [] paginator = cw.get_paginator("list_metrics") for page in paginator.paginate(Namespace="AWS/Logs", MetricName="IncomingBytes"): for metric in page["Metrics"]: + if not metric["Dimensions"]: + continue query = { "Id": f"q{n}", "MetricStat": { @@ -35,8 +37,6 @@ for page in paginator.paginate(Namespace="AWS/Logs", MetricName="IncomingBytes") "Stat": "Sum", }, } - if not metric["Dimensions"]: - continue query_names[f"q{n}"] = metric["Dimensions"][0]["Value"] n = n + 1 queries.append(query) @@ -62,13 +62,12 @@ for data_page in data_paginator.paginate( results.sort(key=lambda x: x["IncomingBytes"], reverse=True) incoming_bytes_total = 0 - for result in results: incoming_bytes_total += result["IncomingBytes"] print("{LogGroup}: {IncomingBytes}".format(**result)) -# CloudWatch logs: 5GiB free ingestion then $0.50 / GiB # Estimate a monthly cost by doubling the incoming_bytes counted over the last 14 days incoming_gb = 2 * incoming_bytes_total / (1024 * 1024 * 1024) +# CloudWatch logs: 5GiB free ingestion then $0.50 / GiB cost = (incoming_gb - 5.0) * 0.5 print(f"Estimated monthly cost: ${cost:.2f}")