AWS Cost Explorer basics - Time & Space Complexity
We want to understand how the time to get cost data changes as we ask for more information in AWS Cost Explorer.
Specifically, how does the number of API calls grow when we request cost details for many resources or time periods?
Analyze the time complexity of the following operation sequence.
# Using AWS CLI to get cost and usage data
aws ce get-cost-and-usage \
--time-period Start=2024-01-01,End=2024-01-31 \
--granularity DAILY \
--metrics "BlendedCost" "UsageQuantity" \
--group-by Type=DIMENSION,Key=SERVICE
This command fetches daily cost and usage data grouped by AWS service for one month.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: The single API call to
get-cost-and-usagerequesting grouped daily data. - How many times: One call per request, but the data returned grows with the number of days and services.
As you ask for more days or more services, the amount of data returned grows roughly by multiplying these factors.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 days, 5 services | 1 call, data for 50 items |
| 30 days, 10 services | 1 call, data for 300 items |
| 90 days, 20 services | 1 call, data for 1800 items |
Pattern observation: The number of data points grows with days times services, but the API call count stays the same.
Time Complexity: O(1)
This means the number of API calls stays the same no matter how much data you request, but the data size returned grows with input.
[X] Wrong: "Requesting more days or services means more API calls will be made automatically."
[OK] Correct: Actually, one API call returns all requested data; the call count does not increase with data size.
Understanding how API calls scale with data requests helps you design efficient cloud cost monitoring tools and shows you think about resource use carefully.
"What if we changed the grouping from SERVICE to TAG? How would the time complexity change?"