steampipe plugin install aws

Table: aws_cost_by_region_monthly - Query AWS Cost Explorer region using SQL

The AWS Cost Explorer region provides detailed information about your AWS costs, enabling you to analyze your costs and usage over time. You can use it to identify trends, isolate cost drivers, and detect anomalies. With SQL queries, you can retrieve monthly cost data specific to each AWS region.

Table Usage Guide

The aws_cost_by_region_monthly table in Steampipe provides you with information about the monthly cost breakdown by region within AWS Cost Explorer. This table allows you, as a financial analyst, DevOps engineer, or other stakeholder, to query cost-specific details, including the region name, the cost associated with it, and the currency code. You can utilize this table to gather insights on cost management, such as tracking AWS expenses, identifying cost trends, and auditing. The schema outlines the various attributes of the cost information, including the region name, cost, and currency code.

Amazon Cost Explorer helps you visualize, understand, and manage your AWS costs and usage. The aws_cost_by_region_monthly table provides you with a simplified view of cost for regions in your account (or all linked accounts when run against the organization master), summarized by month, for the last year.

Important Notes

Examples

Basic info

Explore which AWS regions have the highest costs over time. This query is useful in identifying potential areas for cost reduction through region optimization or consolidation.

select
region,
period_start,
blended_cost_amount :: numeric :: money,
unblended_cost_amount :: numeric :: money,
amortized_cost_amount :: numeric :: money,
net_unblended_cost_amount :: numeric :: money,
net_amortized_cost_amount :: numeric :: money
from
aws_cost_by_region_monthly
order by
region,
period_start;
select
region,
period_start,
cast(blended_cost_amount as decimal),
cast(unblended_cost_amount as decimal),
cast(amortized_cost_amount as decimal),
cast(net_unblended_cost_amount as decimal),
cast(net_amortized_cost_amount as decimal)
from
aws_cost_by_region_monthly
order by
region,
period_start;

Min, Max, and average monthly unblended_cost_amount by region

Explore which AWS regions have the lowest, highest, and average monthly costs, providing a clear understanding of your AWS expenditure. This can help in budgeting and identifying regions that may be costing more than expected.

select
region,
min(unblended_cost_amount) :: numeric :: money as min,
max(unblended_cost_amount) :: numeric :: money as max,
avg(unblended_cost_amount) :: numeric :: money as average
from
aws_cost_by_region_monthly
group by
region
order by
region;
select
region,
min(unblended_cost_amount) as min,
max(unblended_cost_amount) as max,
avg(unblended_cost_amount) as average
from
aws_cost_by_region_monthly
group by
region
order by
region;

Top 10 most expensive region (by average monthly unblended_cost_amount)

Discover the segments that are incurring the highest average monthly costs on your AWS account. This information can be crucial for budgeting and cost management strategies, helping you to identify areas where expenses can be reduced.

select
region,
sum(unblended_cost_amount) :: numeric :: money as sum,
avg(unblended_cost_amount) :: numeric :: money as average
from
aws_cost_by_region_monthly
group by
region
order by
average desc
limit
10;
select
region,
sum(unblended_cost_amount) as sum,
avg(unblended_cost_amount) as average
from
aws_cost_by_region_monthly
group by
region
order by
average desc
limit
10;

Top 10 most expensive region (by total monthly unblended_cost_amount)

This query helps to pinpoint the top 10 most costly regions in terms of total monthly unblended cost. It is useful for gaining insights into where the majority of your AWS costs are coming from, allowing for more informed budgeting and cost management decisions.

select
region,
sum(unblended_cost_amount) :: numeric :: money as sum,
avg(unblended_cost_amount) :: numeric :: money as average
from
aws_cost_by_region_monthly
group by
region
order by
sum desc
limit
10;
select
region,
sum(unblended_cost_amount) as sum,
avg(unblended_cost_amount) as average
from
aws_cost_by_region_monthly
group by
region
order by
sum desc
limit
10;

Ranked - Most expensive month (unblended_cost_amount) by region

This query is designed to identify the most costly month for each region in terms of unblended costs. It can be useful for budgeting and cost management, helping to highlight areas where expenses may be unexpectedly high.

with ranked_costs as (
select
region,
period_start,
unblended_cost_amount :: numeric :: money,
rank() over(
partition by region
order by
unblended_cost_amount desc
)
from
aws_cost_by_region_monthly
)
select
*
from
ranked_costs
where
rank = 1;
Error: SQLite does not support the rank window function.

Month on month growth (unblended_cost_amount) by region

Analyze your AWS monthly costs to understand the percentage change in expenditure for each region. This could be useful for identifying trends, managing budgets, and making strategic decisions about resource allocation.

with cost_data as (
select
region,
period_start,
unblended_cost_amount as this_month,
lag(unblended_cost_amount, -1) over(
partition by region
order by
period_start desc
) as previous_month
from
aws_cost_by_region_monthly
)
select
region,
period_start,
this_month :: numeric :: money,
previous_month :: numeric :: money,
case
when previous_month = 0
and this_month = 0 then 0
when previous_month = 0 then 999
else round(
(100 * ((this_month - previous_month) / previous_month)) :: numeric,
2
)
end as percent_change
from
cost_data
order by
region,
period_start;
with cost_data as (
select
region,
period_start,
unblended_cost_amount as this_month,
lag(unblended_cost_amount, -1) over(
partition by region
order by
period_start desc
) as previous_month
from
aws_cost_by_region_monthly
)
select
region,
period_start,
this_month,
previous_month,
case
when previous_month = 0
and this_month = 0 then 0
when previous_month = 0 then 999
else round(
(100 * ((this_month - previous_month) / previous_month)),
2
)
end as percent_change
from
cost_data
order by
region,
period_start;

Schema for aws_cost_by_region_monthly

NameTypeOperatorsDescription
_ctxjsonbSteampipe context in JSON form.
amortized_cost_amountdouble precisionThis cost metric reflects the effective cost of the upfront and monthly reservation fees spread across the billing period. By default, Cost Explorer shows the fees for Reserved Instances as a spike on the day that you're charged, but if you choose to show costs as amortized costs, the costs are amortized over the billing period. This means that the costs are broken out into the effective daily rate. AWS estimates your amortized costs by combining your unblended costs with the amortized portion of your upfront and recurring reservation fees.
amortized_cost_unittextUnit type for amortized costs.
blended_cost_amountdouble precisionThis cost metric reflects the average cost of usage across the consolidated billing family. If you use the consolidated billing feature in AWS Organizations, you can view costs using blended rates.
blended_cost_unittextUnit type for blended costs.
estimatedbooleanWhether the result is estimated.
net_amortized_cost_amountdouble precisionThis cost metric amortizes the upfront and monthly reservation fees while including discounts such as RI volume discounts.
net_amortized_cost_unittextUnit type for net amortized costs.
net_unblended_cost_amountdouble precisionThis cost metric reflects the unblended cost after discounts.
net_unblended_cost_unittextUnit type for net unblended costs.
normalized_usage_amountdouble precisionThe amount of usage that you incurred, in normalized units, for size-flexible RIs. The NormalizedUsageAmount is equal to UsageAmount multiplied by NormalizationFactor.
normalized_usage_unittextUnit type for normalized usage.
period_endtimestamp with time zoneEnd timestamp for this cost metric.
period_starttimestamp with time zoneStart timestamp for this cost metric.
regiontext=, !=The name of the AWS region.
sp_connection_nametext=, !=, ~~, ~~*, !~~, !~~*Steampipe connection name.
sp_ctxjsonbSteampipe context in JSON form.
unblended_cost_amountdouble precisionUnblended costs represent your usage costs on the day they are charged to you. In finance terms, they represent your costs on a cash basis of accounting.
unblended_cost_unittextUnit type for unblended costs.
usage_quantity_amountdouble precisionThe amount of usage that you incurred. NOTE: If you return the UsageQuantity metric, the service aggregates all usage numbers without taking into account the units. For example, if you aggregate usageQuantity across all of Amazon EC2, the results aren't meaningful because Amazon EC2 compute hours and data transfer are measured in different units (for example, hours vs. GB).
usage_quantity_unittextUnit type for usage quantity.

Export

This table is available as a standalone Exporter CLI. Steampipe exporters are stand-alone binaries that allow you to extract data using Steampipe plugins without a database.

You can download the tarball for your platform from the Releases page, but it is simplest to install them with the steampipe_export_installer.sh script:

/bin/sh -c "$(curl -fsSL https://steampipe.io/install/export.sh)" -- aws

You can pass the configuration to the command with the --config argument:

steampipe_export_aws --config '<your_config>' aws_cost_by_region_monthly