Skip to content

Add table detailed billing report #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aws/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/turbot/tailpipe-plugin-aws/tables/alb_access_log"
"github.com/turbot/tailpipe-plugin-aws/tables/clb_access_log"
"github.com/turbot/tailpipe-plugin-aws/tables/cloudtrail_log"
"github.com/turbot/tailpipe-plugin-aws/tables/detailed_billing_report"
"github.com/turbot/tailpipe-plugin-aws/tables/nlb_access_log"
"github.com/turbot/tailpipe-plugin-aws/tables/s3_server_access_log"
"github.com/turbot/tailpipe-plugin-aws/tables/vpc_flow_log"
Expand All @@ -26,6 +27,7 @@ func init() {
// 2. table implementation
table.RegisterTable[*alb_access_log.AlbAccessLog, *alb_access_log.AlbAccessLogTable]()
table.RegisterTable[*cloudtrail_log.CloudTrailLog, *cloudtrail_log.CloudTrailLogTable]()
table.RegisterTable[*detailed_billing_report.DetailedBillingReport, *detailed_billing_report.DetailedBillingReportTable]()
table.RegisterTable[*nlb_access_log.NlbAccessLog, *nlb_access_log.NlbAccessLogTable]()
table.RegisterTable[*s3_server_access_log.S3ServerAccessLog, *s3_server_access_log.S3ServerAccessLogTable]()
table.RegisterTable[*vpc_flow_log.VpcFlowLog, *vpc_flow_log.VpcFlowLogTable]()
Expand Down
1 change: 1 addition & 0 deletions docs/sources/aws_s3_bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ The following tables define their own default values for certain source argument
- **[aws_cloudtrail_log](https://hub.tailpipe.io/plugins/turbot/aws/tables/aws_cloudtrail_log#aws_s3_bucket)**
- **[aws_nlb_access_log](https://hub.tailpipe.io/plugins/turbot/aws/tables/aws_nlb_access_log#aws_s3_bucket)**
- **[aws_s3_server_access_log](https://hub.tailpipe.io/plugins/turbot/aws/tables/aws_s3_server_access_log#aws_s3_bucket)**
- **[aws_detailed_billing_report](https://hub.tailpipe.io/plugins/turbot/aws/tables/aws_detailed_billing_report#aws_s3_bucket)**
- **[aws_vpc_flow_log](https://hub.tailpipe.io/plugins/turbot/aws/tables/aws_vpc_flow_log#aws_s3_bucket)**
- **[aws_waf_traffic_log](https://hub.tailpipe.io/plugins/turbot/aws/tables/aws_waf_traffic_log#aws_s3_bucket)**
186 changes: 186 additions & 0 deletions docs/tables/aws_detailed_billing_report/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
---
title: "Tailpipe Table: aws_detailed_billing_report - Query AWS Detailed Billing Reports"
description: "AWS Detailed Billing Report provides comprehensive information on AWS costs, usage, and billing details for your AWS accounts."
---

# Table: aws_detailed_billing_report - Query AWS Detailed Billing Reports

The `aws_detailed_billing_report` table allows you to query AWS Detailed Billing Report data from AWS. This table provides insights into your AWS billing, usage, resource details, and cost allocations, offering a historical view of your AWS spending before the introduction of the Cost and Usage Reports.

## Configure

Create a [partition](https://tailpipe.io/docs/manage/partition) for `aws_detailed_billing_report` ([examples](https://hub.tailpipe.io/plugins/turbot/aws/tables/aws_detailed_billing_report#example-configurations)):

```sh
vi ~/.tailpipe/config/aws.tpc
```

```hcl
connection "aws" "billing_account" {
profile = "my-billing-account"
}

partition "aws_detailed_billing_report" "my_dbr" {
source "aws_s3_bucket" {
connection = connection.aws.billing_account
bucket = "aws-dbr-billing-bucket"
}
}
```

## Collect

[Collect](https://tailpipe.io/docs/manage/collection) data for all `aws_detailed_billing_report` partitions:

```sh
tailpipe collect aws_detailed_billing_report
```

Or for a single partition:

```sh
tailpipe collect aws_detailed_billing_report.my_dbr
```

## Query

**[Explore 12+ example queries for this table →](https://hub.tailpipe.io/plugins/turbot/aws/queries/aws_detailed_billing_report)**

### Monthly Cost Breakdown

Retrieve the total cost for each month, grouped by AWS account.

```sql
select
date_trunc('month', usage_start_date) as billing_month,
linked_account_id as account_id,
sum(total_cost) as total_cost
from
aws_detailed_billing_report
group by
billing_month, account_id
order by
billing_month desc;
```

### Top 10 Most Expensive AWS Services

List the top 10 AWS services with the highest costs.

```sql
select
product_name,
sum(total_cost) as total_cost
from
aws_detailed_billing_report
group by
product_name
order by
total_cost desc
limit 10;
```

### Cost by Operation

Analyze costs by operation type.

```sql
select
operation,
sum(total_cost) as total_cost,
sum(usage_quantity) as total_usage
from
aws_detailed_billing_report
where
operation is not null
group by
operation
order by
total_cost desc
limit 10;
```

## Example Configurations

### Collect Detailed Billing Reports from an S3 Bucket

Collect AWS DBR files stored in an S3 bucket.

```hcl
connection "aws" "billing_account" {
profile = "my-billing-account"
}

partition "aws_detailed_billing_report" "my_dbr" {
source "aws_s3_bucket" {
connection = connection.aws.billing_account
bucket = "aws-dbr-billing-bucket"
}
}
```

### Collect Reports from an S3 Bucket with a Prefix

Collect AWS DBR files stored in an S3 bucket using a prefix.

```hcl
partition "aws_detailed_billing_report" "my_dbr_prefix" {
source "aws_s3_bucket" {
connection = connection.aws.billing_account
bucket = "aws-dbr-billing-bucket"
prefix = "my/prefix/"
}
}
```

### Collect Reports from Local Files

You can also collect AWS DBR files from local files.

```hcl
partition "aws_detailed_billing_report" "local_dbr" {
source "file" {
paths = ["/Users/myuser/aws_dbr"]
file_layout = "%{DATA}.csv"
}
}
```

### Filter Only Compute Costs

Use the filter argument in your partition to collect only compute-related costs.

```hcl
partition "aws_detailed_billing_report" "compute_costs" {
filter = "product_name = 'Amazon Elastic Compute Cloud'"

source "aws_s3_bucket" {
connection = connection.aws.billing_account
bucket = "aws-dbr-billing-bucket"
}
}
```

### Collect Reports for All Accounts in an AWS Organization

For a specific AWS Organization, collect DBR data for all accounts.

```hcl
partition "aws_detailed_billing_report" "org_dbr" {
source "aws_s3_bucket" {
connection = connection.aws.billing_account
bucket = "aws-dbr-org-bucket"
file_layout = "%{DATA}.csv"
}
}
```

## Source Defaults

### aws_s3_bucket

This table sets the following defaults for the [aws_s3_bucket source](https://hub.tailpipe.io/plugins/turbot/aws/sources/aws_s3_bucket#arguments):

| Argument | Default |
| ----------- | ------------- |
| file_layout | `%{DATA}.csv` |
Loading
Loading