cremich / cdk-bill-bot
- понедельник, 27 июня 2022 г. в 00:33:00
The serverless cost optimization bot
This Construct Library provides L2 and L3 constructs for resources to build AWS Cost and Usage reports using the AWS Cloud Development Kit (CDK).
package.json
before it reaches 1.0.0.
Please keep this warning in mind, if you already consider to use Bill in production environments!
Bill enables AWS customers to proactively monitor their infrastructure costs and identify unforeseen expenses in a timely manner. Bill wants to prevent AWS customers from receiving bad surprises in their monthly bill. Therefore he addresses two primary problem areas:
Bill is a happy bot, if you...
By analyzing your cost and usage reports, Bill will inform you about your monthly costs on a daily basis. This way, AWS customers will always have an up-to-date snapshot of how their infrastructure costs are progressing. AWS customers can then take direct action in the event of increased costs to prevent unintended suprises in their bill.
In addition to the daily status report, Bill enables various best practices in the area of cost optimization so that you can reliably control your costs. For example, by setting up multi-level AWS budget notifications or enabling cost anomaly detection and notification once anomalies are detected.
The AWS Cost and Usage Reports (AWS CUR) contains the most comprehensive set of cost and usage data available. You can use Cost and Usage Reports to publish your AWS billing reports to an Amazon Simple Storage Service (Amazon S3) bucket that you own. You can receive reports that break down your costs by the hour, day, or month, by product or product resource, or by tags that you define yourself.
Source: https://docs.aws.amazon.com/cur/latest/userguide/what-is-cur.html
This Construct Library requires the AWS CDK v2 (>= 2.1.0). Please follow the installation to install the AWS CDK.
You can install Bill in two ways. Either using the CDK library package or by provisioning a default and pre-packaged Cloudformation template with your existing AWS accounts.
Bill can be added into your existing Typescript based CDK applications. Simply include the @cremich/cdk-bill-bot
as a dependency within your application using either NPM or Yarn:
npm install @cremich/cdk-bill-bot --save-dev
# or
yarn add @cremich/cdk-bill-bot --save-dev
TO BE ADDED
In order to receive cost and usage reports, you must have an Amazon S3 bucket in your AWS account to receive and store your reports. When using the CostAndUsageReport
construct, an Amazon S3 Bucket is implicitly created for you.
⚠️ Please keep in mind, that cost and usage reports are only supported inus-east-1
. The implicit created Bucket will then also be created inus-east-1
and defaults to the current stack's region.
import { CostAndUsageReport } from "@cremich/cdk-bill-bot";
new CostAndUsageReport(this, "cur", {
compression: Compression.PARQUET,
format: Format.PARQUET,
timeUnit: TimeUnit.DAILY,
});
If you want to provision a custom Amazon S3 bucket, you can use the CURBucket
construct and provide a reference to this bucket to the CUR
construct. This gives you the flexibility, to provision the Amazon S3 bucket in another region while keeping the report provisioned in us-east-1
import { CostAndUsageReport, CURBucket } from "@cremich/cdk-bill-bot";
const curBucket = new CURBucket(this, "bucket");
new CostAndUsageReport(this, "cur", {
bucket: curBucket,
compression: Compression.PARQUET,
format: Format.PARQUET,
timeUnit: TimeUnit.DAILY,
});
After you created your report, you can provision a AWS Glue based data catalog for this. This enables Bill and you to analyze your cost and usage reports using Amazon Athena.
If you want to enable a data catalog on a new provisioned report, you can simply call addDataCatalog()
on your CostAndUsageReport
construct like
import { CostAndUsageReport } from "@cremich/cdk-bill-bot";
const report = new CostAndUsageReport(this, "cur", {
compression: Compression.PARQUET,
format: Format.PARQUET,
timeUnit: TimeUnit.DAILY,
});
report.addDataCatalog();
This will create an AWS Glue crawler to crawl your report data, an AWS Glue database that references your metadata as well as an Athena Workgroup to enable you to query your data using Amazon Athena.
If you would like to enable a data catalog on an existing report, you can use the CostAndUsageDataCatalog
construct independently and reference your existing S3 Bucket:
import { CostAndUsageDataCatalog } from "@cremich/cdk-bill-bot";
new CostAndUsageDataCatalog(this, "costs-catalog", {
curBucket: bucket,
});
TO BE ANSWERED
TO BE ANSWERED
TO BE ANSWERED