From a57d957552c321f13b1a61f6965e9d48720db0e0 Mon Sep 17 00:00:00 2001 From: Till Hohenberger Date: Fri, 19 Aug 2022 13:03:38 +0200 Subject: [PATCH] Add EBS storage to reports Adds report for EBS storage per volume type Also show Snapshot Storage. --- lib/aws-usage-queries.ts | 17 +++++++++++++++++ lib/ebsStorageByAccountView.sql | 29 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 lib/ebsStorageByAccountView.sql diff --git a/lib/aws-usage-queries.ts b/lib/aws-usage-queries.ts index 4ca267c..f3754f4 100644 --- a/lib/aws-usage-queries.ts +++ b/lib/aws-usage-queries.ts @@ -354,5 +354,22 @@ export class AwsUsageQueriesStack extends cdk.Stack { } }); + new GlueView(this, "ebsStorageByAccountView", { + columns: [ + { name: "account_id", type: Schema.STRING }, + { name: "volume_type", type: Schema.STRING }, + { name: "usage_gb", type: Schema.DOUBLE }, + { name: "year", type: Schema.INTEGER }, + { name: "month", type: Schema.INTEGER } + ], + database: database, + tableName: "monthly_ebs_storage_by_account", + description: "Monthly EBS storage by volume type and account", + statement: fs.readFileSync(path.join(__dirname, "ebsStorageByAccountView.sql")).toString(), + placeHolders: { + sourceTable: sourceTable.tableName + } + }); + } } diff --git a/lib/ebsStorageByAccountView.sql b/lib/ebsStorageByAccountView.sql new file mode 100644 index 0000000..a3462f4 --- /dev/null +++ b/lib/ebsStorageByAccountView.sql @@ -0,0 +1,29 @@ +( + SELECT line_item_usage_account_id account_id, + product_volume_api_name volume_type, + sum(line_item_usage_amount) as usage_gb, + year, + month + FROM ${sourceTable} + WHERE product_servicename LIKE '%Amazon Elastic Compute Cloud%' + AND product_usagetype LIKE 'EBS:VolumeUsage%' + GROUP BY line_item_usage_account_id, + product_volume_api_name, + year, + month +) +UNION +( + SELECT line_item_usage_account_id account_id, + product_product_family volume_type, + sum(line_item_usage_amount) as usage_gb, + year, + month + FROM ${sourceTable} + WHERE product_servicename LIKE '%Amazon Elastic Compute Cloud%' + AND product_usagetype LIKE 'EBS:SnapshotUsage%' + GROUP BY line_item_usage_account_id, + product_product_family, + year, + month +) \ No newline at end of file