diff --git a/API.md b/API.md index 9bec43b..1de6c79 100644 --- a/API.md +++ b/API.md @@ -311,13 +311,13 @@ Return default SNS topic only if the defultTopic prop has been passed when insta ```typescript import { ApplicationCostMonitoring } from 'cost-monitoring-construct' -new ApplicationCostMonitoring(stack: Stack, props: IApplicationCostMonitoringProps) +new ApplicationCostMonitoring(stack: Stack, props: ApplicationCostMonitoringProps) ``` | **Name** | **Type** | **Description** | | --- | --- | --- | | stack | aws-cdk-lib.Stack | - default stack to track its resources and it will be used to define Budget resources in it. | -| props | IApplicationCostMonitoringProps | *No description.* | +| props | ApplicationCostMonitoringProps | *No description.* | --- @@ -331,7 +331,7 @@ default stack to track its resources and it will be used to define Budget resour ##### `props`Required -- *Type:* IApplicationCostMonitoringProps +- *Type:* ApplicationCostMonitoringProps --- @@ -445,6 +445,141 @@ public readonly applicationName: string; --- +### ApplicationCostMonitoringProps + +- *Implements:* IApplicationCostMonitoringProps + +#### Initializers + +```typescript +import { ApplicationCostMonitoringProps } from 'cost-monitoring-construct' + +new ApplicationCostMonitoringProps(applicationName: string, monthlyLimitInDollars: number, otherStacksIncludedInBudget?: Stack[], defaultTopic?: string, subscribers?: string[], costAllocationTag?: string) +``` + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| applicationName | string | *No description.* | +| monthlyLimitInDollars | number | *No description.* | +| otherStacksIncludedInBudget | aws-cdk-lib.Stack[] | *No description.* | +| defaultTopic | string | *No description.* | +| subscribers | string[] | *No description.* | +| costAllocationTag | string | *No description.* | + +--- + +##### `applicationName`Required + +- *Type:* string + +--- + +##### `monthlyLimitInDollars`Required + +- *Type:* number + +--- + +##### `otherStacksIncludedInBudget`Optional + +- *Type:* aws-cdk-lib.Stack[] + +--- + +##### `defaultTopic`Optional + +- *Type:* string + +--- + +##### `subscribers`Optional + +- *Type:* string[] + +--- + +##### `costAllocationTag`Optional + +- *Type:* string + +--- + + + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| applicationName | string | *No description.* | +| monthlyLimitInDollars | number | *No description.* | +| costAllocationTag | string | *No description.* | +| defaultTopic | string | *No description.* | +| otherStacksIncludedInBudget | aws-cdk-lib.Stack[] | *No description.* | +| subscribers | string[] | *No description.* | + +--- + +##### `applicationName`Required + +```typescript +public readonly applicationName: string; +``` + +- *Type:* string + +--- + +##### `monthlyLimitInDollars`Required + +```typescript +public readonly monthlyLimitInDollars: number; +``` + +- *Type:* number + +--- + +##### `costAllocationTag`Optional + +```typescript +public readonly costAllocationTag: string; +``` + +- *Type:* string + +--- + +##### `defaultTopic`Optional + +```typescript +public readonly defaultTopic: string; +``` + +- *Type:* string + +--- + +##### `otherStacksIncludedInBudget`Optional + +```typescript +public readonly otherStacksIncludedInBudget: Stack[]; +``` + +- *Type:* aws-cdk-lib.Stack[] + +--- + +##### `subscribers`Optional + +```typescript +public readonly subscribers: string[]; +``` + +- *Type:* string[] + +--- + + ### IBudgetStrategy #### Initializers @@ -572,7 +707,7 @@ Return default SNS topic only if the defultTopic prop has been passed when insta - *Extends:* IBudgetStrategyProps -- *Implemented By:* IApplicationCostMonitoringProps +- *Implemented By:* ApplicationCostMonitoringProps, IApplicationCostMonitoringProps #### Properties @@ -583,6 +718,7 @@ Return default SNS topic only if the defultTopic prop has been passed when insta | defaultTopic | string | *No description.* | | subscribers | string[] | *No description.* | | applicationName | string | *No description.* | +| costAllocationTag | string | *No description.* | | otherStacksIncludedInBudget | aws-cdk-lib.Stack[] | *No description.* | --- @@ -627,6 +763,16 @@ public readonly applicationName: string; --- +##### `costAllocationTag`Optional + +```typescript +public readonly costAllocationTag: string; +``` + +- *Type:* string + +--- + ##### `otherStacksIncludedInBudget`Optional ```typescript @@ -762,7 +908,7 @@ public readonly tags: ITag[]; ### IBudgetStrategyProps -- *Implemented By:* IApplicationCostMonitoringProps, IBudgetStrategyProps +- *Implemented By:* ApplicationCostMonitoringProps, IApplicationCostMonitoringProps, IBudgetStrategyProps #### Properties diff --git a/src/application-cost-monitoring.ts b/src/application-cost-monitoring.ts index 0f04f07..307ad5e 100644 --- a/src/application-cost-monitoring.ts +++ b/src/application-cost-monitoring.ts @@ -6,11 +6,24 @@ import { TimeUnit } from "./utils"; export interface IApplicationCostMonitoringProps extends IBudgetStrategyProps { applicationName: string; otherStacksIncludedInBudget?: Stack[]; + costAllocationTag?: string; +} + +export class ApplicationCostMonitoringProps implements IApplicationCostMonitoringProps { + constructor( + public applicationName: string, + public monthlyLimitInDollars: number, + public otherStacksIncludedInBudget?: Stack[], + public defaultTopic?: string, + public subscribers?: string[], + public costAllocationTag?: string + ) {} } export class ApplicationCostMonitoring extends IBudgetStrategy { readonly applicationName: string; private otherStacks: Stack[]; + private costAllocationTag?: string /** * Default Application CostMonitoring class that implements daily and monthly budgets. @@ -21,6 +34,7 @@ export class ApplicationCostMonitoring extends IBudgetStrategy { * @param props.monthlyLimitInDollars - montly limit in US Dollors. * @param props.defaultTopic - default SNS topic name. Only if provided, the BudgetStratgy creates an SNS topic and send notifications to it. * @param props.subscribers - list of email address that the CostMonitoring will use to send alerts to. + * @param props.costAllocationTag - Tag key used to track resources' expenditure. Only if provided, it will be used to tag the application resources. * * @example tracking budget for an application called `my-application`: * const app = new cdk.App(); @@ -41,7 +55,7 @@ export class ApplicationCostMonitoring extends IBudgetStrategy { * budgetStratgy.monitor(); * */ - constructor(stack: Stack, props: IApplicationCostMonitoringProps) { + constructor(stack: Stack, props: ApplicationCostMonitoringProps) { super(stack, props); if (props.monthlyLimitInDollars < 30) { @@ -52,6 +66,7 @@ export class ApplicationCostMonitoring extends IBudgetStrategy { this.applicationName = props.applicationName; this.otherStacks = props.otherStacksIncludedInBudget ?? []; + this.costAllocationTag = props.costAllocationTag; } protected createDailyBudgets( @@ -133,6 +148,6 @@ export class ApplicationCostMonitoring extends IBudgetStrategy { * Default key name for application tag. */ protected get applicationTagKey(): string { - return "cm:application"; + return this.costAllocationTag || "cm:application"; } } diff --git a/src/index.ts b/src/index.ts index c1889ef..bbda665 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ export { AccountCostMonitoring } from "./account-cost-monitoring"; export { ApplicationCostMonitoring, + ApplicationCostMonitoringProps, IApplicationCostMonitoringProps, } from "./application-cost-monitoring"; export * from "./budget-strategy";