UNPKG

cost-monitoring-construct

Version:

A CDK construct that helps track applications' costs separately and receive alerts in case of unpredicted resource usage

70 lines (69 loc) 4.12 kB
import { Stack, aws_budgets as budgets } from "aws-cdk-lib"; import { IBudgetStrategyProps, IBudgetStrategy } from "./budget-strategy"; export interface IApplicationCostMonitoringProps extends IBudgetStrategyProps { applicationName: string; otherStacksIncludedInBudget?: Stack[]; costAllocationTag?: string; } export declare class ApplicationCostMonitoringProps implements IApplicationCostMonitoringProps { applicationName: string; monthlyLimitInDollars: number; subscribers: string[]; otherStacksIncludedInBudget?: Stack[] | undefined; defaultTopic?: string | undefined; costAllocationTag?: string | undefined; /** * @param applicationName - the name of application to label resources with it. * @param monthlyLimitInDollars - montly limit in US Dollors. * @param otherStacksIncludedInBudget - optional other stack to track their resources alog with the default stack. * @param defaultTopic - default SNS topic name. Only if provided, the BudgetStratgy creates an SNS topic and send notifications to it. * @param subscribers - list of email address that the CostMonitoring will use to send alerts to. * @param costAllocationTag - Tag key used to track resources' expenditure. Only if provided, it will be used to tag the application resources. Defaults to `cm:application` */ constructor(applicationName: string, monthlyLimitInDollars: number, subscribers: string[], otherStacksIncludedInBudget?: Stack[] | undefined, defaultTopic?: string | undefined, costAllocationTag?: string | undefined); } export declare class ApplicationCostMonitoring extends IBudgetStrategy { readonly applicationName: string; private otherStacks; private costAllocationTag?; /** * Default Application CostMonitoring class that implements daily and monthly budgets. * * @param stack - default stack to track its resources and it will be used to define Budget resources in it. * @param props.applicationName - the name of application to label resources with it. * @param props.otherStacksIncludedInBudget - optional other stack to track their resources alog with the default stack. * @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. Defaults to `cm:application` * * @example * Tracking budget for an application called `my-application` * * const app = new cdk.App(); * const firstStack = new FirstStack(app, 'FirstStack', {}); * const secondStack = new SecondStack(app, 'SecondStack', {}); * const costMonitoring = new ApplicationCostMonitoring(firstStack, { * applicationName: 'my-application', * monthlyLimitInDollars : 200, * otherStacksToMonitor: [secondStack], // Optional (you can add as many stacks as you want) * subscribers: ['alert@mymail.com'] * }); * * budgetStratgy.monitor(); */ constructor(stack: Stack, props: ApplicationCostMonitoringProps); protected createDailyBudgets(dailyLimit: number, subscribers: Array<budgets.CfnBudget.SubscriberProperty>): void; protected createMonthlyBudgets(monthlyLimit: number, subscribers: Array<budgets.CfnBudget.SubscriberProperty>): void; protected createQuarterlyBudgets(_quarterlyLimit: number, _subscribers: budgets.CfnBudget.SubscriberProperty[]): void; protected createYearlyBudgets(_yearlyLimit: number, _subscribers: budgets.CfnBudget.SubscriberProperty[]): void; private tagAllStacks; /** * Creates all the alarms, budgets and tags all resources with the application's name. */ monitor(): void; /** * Default key name for application tag. */ protected get applicationTagKey(): string; }