Skip to content

Commit

Permalink
Add support for Billing CloudWatch metrics and alarms (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
catmeme committed Apr 29, 2021
1 parent 6f2176d commit 4b2ad8c
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ _(none)_
* Upgrade to @pulumi/pulumi@3.0.0 and @pulumi/aws@4.0.0
* 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.0 (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 });
}
}
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

0 comments on commit 4b2ad8c

Please sign in to comment.