0
0
AWScloud~5 mins

AWS Cost Explorer basics - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: AWS Cost Explorer basics
O(1)
Understanding Time 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?

Scenario Under Consideration

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 Repeating Operations

Identify the API calls, resource provisioning, data transfers that repeat.

  • Primary operation: The single API call to get-cost-and-usage requesting grouped daily data.
  • How many times: One call per request, but the data returned grows with the number of days and services.
How Execution Grows With Input

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 services1 call, data for 50 items
30 days, 10 services1 call, data for 300 items
90 days, 20 services1 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.

Final Time Complexity

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.

Common Mistake

[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.

Interview Connect

Understanding how API calls scale with data requests helps you design efficient cloud cost monitoring tools and shows you think about resource use carefully.

Self-Check

"What if we changed the grouping from SERVICE to TAG? How would the time complexity change?"