for result in response["ResultsByTime"]: for group in result["Groups"]: account_id, service = group["Keys"] amount = Decimal(group["Metrics"]["UnblendedCost"]["Amount"]) if amount == 0: continue if account_id not in costs: costs[account_id] = {} # 月跨ぎで同じサービスが複数エントリに分かれるため加算する costs[account_id][service] = costs[account_id].get(service, Decimal("0")) + amount return costs