From 4b2ad8c1f527f3455eb609b4f40208589d3c1fb0 Mon Sep 17 00:00:00 2001 From: catmeme Date: Thu, 29 Apr 2021 11:42:52 -0400 Subject: [PATCH] Add support for Billing CloudWatch metrics and alarms (#659) --- CHANGELOG.md | 1 + nodejs/awsx/billing/index.ts | 15 +++++++ nodejs/awsx/billing/metrics.ts | 79 ++++++++++++++++++++++++++++++++++ nodejs/awsx/index.ts | 2 + 4 files changed, 97 insertions(+) create mode 100644 nodejs/awsx/billing/index.ts create mode 100644 nodejs/awsx/billing/metrics.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index e128e23b6..6d775a802 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/nodejs/awsx/billing/index.ts b/nodejs/awsx/billing/index.ts new file mode 100644 index 000000000..9fd94826b --- /dev/null +++ b/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"; diff --git a/nodejs/awsx/billing/metrics.ts b/nodejs/awsx/billing/metrics.ts new file mode 100644 index 000000000..c071f551f --- /dev/null +++ b/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> = {}; + + 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 }); + } +} diff --git a/nodejs/awsx/index.ts b/nodejs/awsx/index.ts index 9df4f685f..814eb17be 100644 --- a/nodejs/awsx/index.ts +++ b/nodejs/awsx/index.ts @@ -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"; @@ -37,6 +38,7 @@ export { acmpca, apigateway, autoscaling, + billing, cloudfront, cloudtrail, cloudwatch,