AWS Cost Explorer basics - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
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?"
Practice
Solution
Step 1: Understand AWS Cost Explorer's function
AWS Cost Explorer is designed to show your cloud spending clearly and help manage costs.Step 2: Compare options with this function
Options A, B, and D describe other AWS services or features unrelated to cost tracking.Final Answer:
To help you track and understand your AWS spending -> Option CQuick Check:
Cost tracking = C [OK]
- Confusing Cost Explorer with EC2 or IAM services
- Thinking it manages network or security settings
Solution
Step 1: Identify where billing tools are located
Cost Explorer is found under Billing in the AWS Console, not under EC2, IAM, or S3.Step 2: Match the correct navigation path
Only Go to Services > Billing > Cost Explorer correctly shows Services > Billing > Cost Explorer.Final Answer:
Go to Services > Billing > Cost Explorer -> Option DQuick Check:
Billing section = A [OK]
- Looking for Cost Explorer under EC2 or S3
- Confusing IAM with billing tools
Solution
Step 1: Understand grouping by service in Cost Explorer
Grouping by service shows how much money you spent on each AWS service in the selected time.Step 2: Interpret the amounts shown
$100 for EC2 and $50 for S3 means those are your costs, not credits or reserved amounts.Final Answer:
You spent $100 on EC2 and $50 on S3 this month -> Option BQuick Check:
Costs shown = spending, not credits or free usage [OK]
- Thinking amounts are credits or free usage
- Confusing cost with reserved capacity
Solution
Step 1: Understand tag filtering in Cost Explorer
To filter by tags, the tags must be activated for cost allocation in Billing preferences.Step 2: Identify why no data appears
If the tag is not activated, Cost Explorer cannot use it to filter, so no data shows.Final Answer:
The tag is not activated for cost allocation in AWS Billing settings -> Option AQuick Check:
Tag activation needed for filtering = A [OK]
- Assuming Cost Explorer can't filter by tags
- Thinking AWS instance restart fixes this
- Believing no AWS account is the cause
Solution
Step 1: Choose correct time range and grouping
Set the time range to last 3 months and group by linked accounts to see costs per account.Step 2: Apply service filters correctly
Filter services to only EC2 and S3 to focus on those costs.Step 3: Verify options
Set the time range to last 3 months, group by linked accounts, and filter services to EC2 and S3 matches all requirements. Other options have wrong grouping, filtering, or time range.Final Answer:
Set the time range to last 3 months, group by linked accounts, and filter services to EC2 and S3 -> Option AQuick Check:
Time + grouping + filter = B [OK]
- Mixing grouping by service vs linked accounts
- Filtering accounts instead of services
- Choosing wrong time range
