steampipe plugin install aws

Table: aws_cost_by_record_type_monthly - Query AWS Cost and Usage Report Records using SQL

The AWS Cost and Usage Report service provides comprehensive cost and usage data about your AWS resources, enabling you to manage your costs and optimize your AWS spend. It records the AWS usage data for your accounts and delivers the log files to a specified Amazon S3 bucket. You can query these records using SQL to gain insights into your resource usage and cost.

Table Usage Guide

The aws_cost_by_record_type_monthly table in Steampipe provides you with information about AWS Cost and Usage Report Records, specifically detailing costs incurred by different record types on a monthly basis. This table allows you, whether you're a DevOps engineer or a financial analyst, to query cost-specific details, including service usage, cost allocation, and associated metadata. You can utilize this table to gather insights on AWS costs, such as costs associated with specific AWS services, cost trends over time, and cost allocation across different record types. The schema outlines the various attributes of the cost and usage report record, including the record type, usage type, operation, and cost.

Amazon Cost Explorer helps you visualize, understand, and manage your AWS costs and usage. The aws_cost_by_record_type_monthly table provides a simplified view of cost for your account (or all linked accounts when run against the organization master) as per record types (fees, usage, costs, tax refunds, and credits), summarized by month, for the last year.

Important Notes

Examples

Basic info

Gain insights into your AWS cost trends by analyzing monthly expenses. This query helps in understanding the cost incurred over time, aiding in effective budget planning and cost management.

select
linked_account_id,
record_type,
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_record_type_monthly
order by
linked_account_id,
period_start;
select
linked_account_id,
record_type,
period_start,
CAST(blended_cost_amount AS REAL) AS blended_cost_amount,
CAST(unblended_cost_amount AS REAL) AS unblended_cost_amount,
CAST(amortized_cost_amount AS REAL) AS amortized_cost_amount,
CAST(net_unblended_cost_amount AS REAL) AS net_unblended_cost_amount,
CAST(net_amortized_cost_amount AS REAL) AS net_amortized_cost_amount
from
aws_cost_by_record_type_monthly
order by
linked_account_id,
period_start;

Min, Max, and average monthly unblended_cost_amount by account and record type

Explore which linked accounts have the highest, lowest, and average monthly costs, grouped by record type. This can help in understanding the cost distribution and identifying any unusual spending patterns.

select
linked_account_id,
record_type,
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_record_type_monthly
group by
linked_account_id,
record_type
order by
linked_account_id;
select
linked_account_id,
record_type,
min(unblended_cost_amount) as min,
max(unblended_cost_amount) as max,
avg(unblended_cost_amount) as average
from
aws_cost_by_record_type_monthly
group by
linked_account_id,
record_type
order by
linked_account_id;

Ranked - Most expensive months (unblended_cost_amount) by account and record type

Explore which months have been the most costly for each account and record type. This can aid in identifying trends and planning future budgeting strategies.

select
linked_account_id,
record_type,
period_start,
unblended_cost_amount :: numeric :: money,
rank() over(
partition by linked_account_id,
record_type
order by
unblended_cost_amount desc
)
from
aws_cost_by_record_type_monthly;
select
linked_account_id,
record_type,
period_start,
unblended_cost_amount,
(
select
count(*) + 1
from
aws_cost_by_record_type_monthly as b
where
a.linked_account_id = b.linked_account_id
and a.record_type = b.record_type
and a.unblended_cost_amount < b.unblended_cost_amount
)
from
aws_cost_by_record_type_monthly as a;

Schema for aws_cost_by_record_type_monthly

NameTypeOperatorsDescription
_ctxjsonbSteampipe context in JSON form, e.g. connection_name.
account_idtextThe 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.
linked_account_idtextThe linked AWS Account ID.
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.
record_typetextThe different types of charges such as RI fees, usage, costs, tax refunds, and credits.
regiontextThe AWS Region in which the resource is located.
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_record_type_monthly