2828from .prometheus import Prometheus
2929
3030logger = get_logger (__name__ )
31- aws_ce_client = boto3 .client ("ce" )
3231
3332
3433class AWSCostExplorer (LoggingConfigurable ):
@@ -47,13 +46,17 @@ def _get_component_name(self, service_name):
4746 klass = Prometheus ,
4847 )
4948
49+ def __init__ (self , * args , ** kwargs ):
50+ super ().__init__ (* args , ** kwargs )
51+ self .aws_ce_client = boto3 .client ("ce" )
52+
5053 def query (self , metrics , granularity , from_date , to_date , filter , group_by ):
5154 """
5255 Function meant to be responsible for making the API call and handling
5356 pagination etc. Currently pagination isn't handled.
5457 """
5558 # ref: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ce/client/get_cost_and_usage.html#get-cost-and-usage
56- response = aws_ce_client .get_cost_and_usage (
59+ response = self . aws_ce_client .get_cost_and_usage (
5760 Metrics = metrics ,
5861 Granularity = granularity ,
5962 TimePeriod = {"Start" : from_date , "End" : to_date },
@@ -86,7 +89,7 @@ def query_hub_names(self, date_range: DateRange):
8689 from_date , to_date = date_range .aws_range
8790
8891 # ref: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ce/client/get_tags.html
89- response = aws_ce_client .get_tags (
92+ response = self . aws_ce_client .get_tags (
9093 TimePeriod = {"Start" : from_date , "End" : to_date },
9194 TagKey = "2i2c:hub-name" ,
9295 )
0 commit comments