Skip to content
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

Add support for Billing CloudWatch metrics and alarms #659

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@ CHANGELOG

* Add additional StorageTypes to `awsx.s3.metrics`
* Add missing `HEAD` value to `awsx.apigateway.Method`
* Add support for Billing CloudWatch metrics and alarms

## 0.26 (2021-03-25)

Expand Down
15 changes: 15 additions & 0 deletions nodejs/awsx/billing/index.ts
@@ -0,0 +1,15 @@
// Copyright 2016-2018, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

export * from "./metrics";
79 changes: 79 additions & 0 deletions nodejs/awsx/billing/metrics.ts
@@ -0,0 +1,79 @@
// Copyright 2016-2018, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import * as pulumi from "@pulumi/pulumi";

import * as cloudwatch from "../cloudwatch";

export namespace metrics {
type BillingMetricName =
"EstimatedCharges";

export interface BillingMetricChange extends cloudwatch.MetricChange {
/**
* Optional Currency dimension
*/
currency: "USD";
/**
* Optional linked Amazon account id
*/
linkedAccount?: string;
/**
* Optional Service this metric should be filtered down to.
*/
serviceName?: "AmazonCloudWatch" | "AmazonEC2" | "AmazonKinesis" | "AmazonRoute53" | "AmazonS3" |
"AmazonSNS" | "AWSCloudTrail" | "AWSCodePipeline" | "AWSConfig" | "AWSDataTransfer" |
"awskms" | "AWSLambda" | "AWSMarketplace" | "AWSQueueService" | "AWSSecretsManager" |
"awswaf" | "AWSXRay" | "CodeBuild";
}

/**
* Creates an AWS/Billing metric with the requested [metricName]. See
* https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/monitor_estimated_charges_with_cloudwatch.html
* for more information.
*/
function metric(metricName: BillingMetricName, change: BillingMetricChange = {
currency: "USD",
}) {
const dimensions: Record<string, pulumi.Input<string>> = {};

if (change.currency !== undefined) {
dimensions.Currency = change.currency;
}

if (change.linkedAccount !== undefined) {
dimensions.LinkedAccount = change.linkedAccount;
}

if (change.serviceName !== undefined) {
dimensions.ServiceName = change.serviceName;
}

return new cloudwatch.Metric({
namespace: "AWS/Billing",
name: metricName,
...change,
}).withDimensions(dimensions);
}

/**
* EstimatedCharges
*
* Units: currency
* Valid CloudWatch statistics: Average, Maximum (recommended), Minimum
*/
export function estimatedCharges(change?: BillingMetricChange) {
return metric("EstimatedCharges", { statistic: "Maximum", currency: "USD", ...change });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the question for me here is can "Statistic" and "currency" be anything other than these values above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Statistic looks like it accepts the usual values, however, I was unable to find a list of supported currencies, and the only thing I've found is "USD".

}
}
2 changes: 2 additions & 0 deletions nodejs/awsx/index.ts
Expand Up @@ -15,6 +15,7 @@
import * as acmpca from "./acmpca";
import * as apigateway from "./apigateway";
import * as autoscaling from "./autoscaling";
import * as billing from "./billing";
import * as cloudfront from "./cloudfront";
import * as cloudtrail from "./cloudtrail";
import * as cloudwatch from "./cloudwatch";
Expand All @@ -37,6 +38,7 @@ export {
acmpca,
apigateway,
autoscaling,
billing,
cloudfront,
cloudtrail,
cloudwatch,
Expand Down