Query Builder

Query Builder

The Query Builder in Cost Explorer allows you to create custom cost analyses by combining filters, groupings, and date ranges.

Accessing Cost Explorer

Navigate to Cost Explorer in the main menu. The page shows your filter controls and the results (chart and table) all in one view. Adjust the filters and the results update automatically.

Cost Explorer UI Cost Explorer UI

Query Components

Date Range

Select the time period for analysis using the calendar date picker. Click the date range field to open the calendar and choose a start and end date.

Filters

Narrow down results by dimension:

FilterDescription
ServiceAWS service (EC2, RDS, S3, Lambda, etc.)
AccountAWS account ID
RegionAWS region
Usage TypeSpecific usage categories
OperationAWS operation type
Instance TypeEC2/RDS instance type
Availability ZoneSpecific AZ
Resource IDIndividual resource identifier
TagCost allocation tags (prefix with tag:)

Multiple Filters

Combine filters for precise analysis:

Service = EC2
  AND Region = us-east-1
  AND Tag:Environment = production

Group By

Choose how to aggregate costs:

Group ByResult
ServiceCosts per AWS service
AccountCosts per AWS account
RegionCosts per region
Usage TypeDetailed usage breakdown
Availability ZoneCosts per AZ
OperationCosts per AWS operation type
Instance TypeCosts per EC2/RDS instance type
Resource IDCosts per individual resource
Environment TagCosts grouped by the Environment tag value
Application TagCosts grouped by the Application tag value

Note: Tag-based Group By dimensions (Environment Tag, Application Tag) require the corresponding cost allocation tags to be activated in your AWS Billing Console and enabled in Project Defaults.

Granularity

Choose the time granularity for time series data:

GranularityDescription
DailyDay-by-day cost breakdown (default)
WeeklyWeek-by-week cost breakdown
MonthlyMonth-by-month cost breakdown

Visualization Type

Choose how to display query results:

TypeDescription
Time SeriesLine chart showing costs over time
PiePie chart for proportional breakdown
BarBar chart for comparative analysis
StackedStacked area chart for cumulative trends
TableTabular view of raw results

Metric (Chart Series)

Choose which cost metric to display:

MetricDescription
Unblended CostStandard AWS cost (default)
Blended CostCost averaged across reserved and on-demand usage
Usage AmountResource usage quantity instead of dollar cost

Building a Query

Example 1: EC2 Costs by Region

  1. Date Range: Select the previous month
  2. Filters: Service = Amazon EC2
  3. Group By: Region
  4. Run Query

Example 2: Production Environment Costs

  1. Date Range: Select the last 3 months
  2. Group By: Environment Tag
  3. Run Query

Example 3: Account Comparison

  1. Date Range: Select the last 6 months
  2. Filters: None (all accounts)
  3. Group By: Account
  4. Run Query

Understanding Results

Table View

Results display in a table with:

ColumnDescription
DimensionGrouped values (service, account, etc.)
CostTotal cost for the period
% of TotalProportion of total spend
ChangeDifference from previous period

Chart View

Visualizations available:

  • Line Chart - Trends over time
  • Bar Chart - Comparative analysis
  • Pie Chart - Proportional breakdown
  • Stacked Area - Cumulative trends

Exporting Results

CSV export from Cost Explorer is not yet available. To export cost data, use the AWS Cost Explorer console directly or download reports via Automation Reports.

Query Tips

Performance

  • Shorter date ranges run faster
  • Fewer filters = faster queries
  • Large accounts may have query limits

Accuracy

  • Data has 24-48 hour delay
  • Forecasts are estimates
  • Credits/refunds may appear later

Common Query Patterns

GoalFiltersGroup ByGranularity
Service breakdownNoneServiceMonthly
Regional analysisNoneRegionMonthly
Account comparisonNoneAccountMonthly
Daily spend trendsNoneServiceDaily
Environment costsNoneEnvironment TagMonthly

Troubleshooting

IssueCauseSolution
No resultsFilter too restrictiveBroaden filters
Slow queryLarge date rangeNarrow date range
Missing dataTag not activatedEnable cost allocation tag
Zero costsWrong filter valueVerify filter values