steampipe plugin install aws

Table: aws_cost_by_tag - Query AWS Cost Explorer using SQL

The AWS Cost Explorer is a tool that enables you to view and analyze your costs and usage. You can explore your AWS costs using an interface that allows you to break down costs by AWS service, linked account, tag, and many other dimensions. Through the AWS Cost Explorer API, you can directly access this data and use it to create your own cost management applications.

Table Usage Guide

The aws_cost_by_tag table in Steampipe provides you with information about cost allocation tags and associated costs within AWS Cost Explorer. This table allows you, as a financial analyst, cloud economist, or DevOps engineer, to query cost-specific details, including costs associated with each tag. You can utilize this table to gather insights on cost allocation, such as identifying the most expensive tags, tracking costs of specific projects, departments, or services, and more. The schema outlines the various attributes of the cost allocation tag, including the tag key, cost, and currency.

Amazon Cost Explorer helps you visualize, understand, and manage your AWS costs and usage. The aws_cost_by_tag table provides you with a simplified view of cost by tags in your account. You must specify a granularity (MONTHLY, DAILY) and tag_key_1 to query the table, however, tag_key_2 is optional.

Important Notes

Examples

Basic info

This query is used to gain insights into the daily cost breakdown of AWS services, based on specific tags. It is particularly useful for tracking and managing costs, especially in scenarios where resources are tagged by project, department, or any other category for cost allocation.

select
tag_key_1,
tag_value_1,
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_tag
where
granularity = 'DAILY'
and tag_key_1 = 'Name';
select
tag_key_1,
tag_value_1,
period_start,
CAST(blended_cost_amount AS NUMERIC) AS blended_cost_amount,
CAST(unblended_cost_amount AS NUMERIC) AS unblended_cost_amount,
CAST(amortized_cost_amount AS NUMERIC) AS amortized_cost_amount,
CAST(net_unblended_cost_amount AS NUMERIC) AS net_unblended_cost_amount,
CAST(net_amortized_cost_amount AS NUMERIC) AS net_amortized_cost_amount
from
aws_cost_by_tag
where
granularity = 'DAILY'
and tag_key_1 = 'Name';

Min, Max, and average daily unblended_cost_amount by tag

Discover the segments that have the lowest, highest, and average daily costs associated with a specific tag. This is useful for tracking and managing AWS costs on a day-to-day basis by identifying areas where spending is concentrated.

select
tag_key_1,
tag_value_1,
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_tag
where
granularity = 'DAILY'
and tag_key_1 = 'Name'
group by
tag_key_1,
tag_value_1;
select
tag_key_1,
tag_value_1,
min(unblended_cost_amount) as min,
max(unblended_cost_amount) as max,
avg(unblended_cost_amount) as average
from
aws_cost_by_tag
where
granularity = 'DAILY'
and tag_key_1 = 'Name'
group by
tag_key_1,
tag_value_1;

Ranked - Top 10 Most expensive days (unblended_cost_amount) by tag

Discover the segments that are the top 10 most costly, based on daily expenditures, to identify potential areas of cost reduction. This is particularly useful for those looking to optimize their resource utilization and manage their budget effectively.

with ranked_costs as (
select
tag_key_1,
tag_value_1,
period_start,
unblended_cost_amount :: numeric :: money,
rank() over(
partition by tag_key_1
order by
unblended_cost_amount desc
)
from
aws_cost_by_tag
where
granularity = 'DAILY'
and tag_key_1 = 'Name'
)
select
*
from
ranked_costs
where
rank <= 10;
Error: SQLite does not support the rank window function.

Schema for aws_cost_by_tag

NameTypeOperatorsDescription
_ctxjsonbSteampipe context in JSON form.
account_idtext=, !=, ~~, ~~*, !~~, !~~*The AWS Account ID in which the resource is located.
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.
granularitytext=The granularity for cost and usage metric data. Possible values are: DAILY|MONTHLY.
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.
partitiontextThe AWS partition in which the resource is located (aws, aws-cn, or aws-us-gov).
period_endtimestamp with time zoneEnd timestamp for this cost metric.
period_starttimestamp with time zoneStart timestamp for this cost metric.
regiontextThe AWS Region in which the resource is located.
sp_connection_nametext=, !=, ~~, ~~*, !~~, !~~*Steampipe connection name.
sp_ctxjsonbSteampipe context in JSON form.
tag_key_1text=The tag key to group by.
tag_key_2text=, !=A secondary tag key to group by.
tag_value_1textThe primary tag value grouped by.
tag_value_2textA secondary tag value grouped by.
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_tag