Skip to content

Latest commit

 

History

History
1268 lines (745 loc) · 49 KB

API.md

File metadata and controls

1268 lines (745 loc) · 49 KB

What is Cost Monitoring Construct?

Cost Monitoring Construct is a CDK library that helps monitor costs for AWS cloud infrastructure resources, such as virtual machines, storage, and network traffic. It allows you to set budgets and alerts to ensure that you don't overspend on your cloud resources.

With the Cost Monitoring Construct, you can share the responsibility of cost management between developers and business holders. This is achieved through the creation of meaningful reports that enable the business team to make informed decisions. Additionally, the Construct generates boilerplate code that can be used to apply these decisions in practice, making it easier to stay on top of your budget.

How to use Cost Monitoring Construct?

To use Cost Monitoring Construct, all you need is to have the AWS CDK installed and set up. Once you have that, you can install the package from the repository of your choice.

For more information on using this Construct in TypeScript checkout the TypeScript documentation. You can also check the typescript example from sample folder on the GitHub repository.

Why do you need it?

Cloud services can get very expensive, very quickly, especially if you are not careful with your usage. Cost Monitoring Construct helps you to keep an eye on your cloud infrastructure costs so that you can stay within budget. By setting budgets and defining alert strategies, you can take proactive steps to reduce costs before they become a problem.

How does Cost Monitoring Construct work?

Cost Monitoring Construct uses AWS Tagging practice to track resources related to an specific application, creates proper alert with respect to the defined budget limit and provide overview dashbords. The tool is highly customizable and allows you to customize it to your budgeting strategy based on your specific needs.

Cost Monitoring Construct provides the following features:

  • Cost dashboard: Displays your current costs and usage, broken down by application's name, region, and etc. Allows you to see how much you are spending on each application and where you might be able to reduce costs.
  • Budgets: Allows you to set budgets for each applications. It will automatically set up alerts to notify you when your actual costs exceed your budgeted costs. It also continues to track the cost and sending alert if an application continues to cost drastically.
  • Integration: Integrates with various tools and monitoring services, such as AWS Cost Explorer and Datadog.

Warning

ApplicationCostMonitoring uses AWS Tags to track resources' usages. You must activate your chosen tag key (cm:application by default) under Cost Allocation Tags. The tag key will appear in the AWS console up to 24 hours after at least one AWS resource has been created with that tag.

What is it useful for?

Cost Monitoring Construct is useful for anyone who uses AWS and wants to keep their costs under control. It is particularly useful for:

  • Startups and small businesses: Cost Monitoring Construct can help startups and small businesses to keep their costs under control during the early stages of growth.
  • Large enterprises: Cost Monitoring Construct can help large enterprises to optimize their cloud usage and reduce costs across multiple teams and departments.
  • Developers: Cost Monitoring Construct can help developers to track their usage and costs across multiple projects and services.

What is this not useful for?

The Cost Monitoring Construct is not a magical tool that can solve all of your cloud cost problems. In spite of the fact that it can bring clarity and help you to identify areas where you can reduce costs, you must make the necessary decisions about your infrastructure on your own.

Which programming languages Cost Monitoring Construct supports?

Cost Monitoring Construct has been developed using JSII technolgy to provide interfaces for different modern programming languages. Currently, it supports the following languages:

Note

Go will be supported soon but for now you can build it from the source.

If you have any questions or need help with Cost Monitoring Construct, you can reach out to our support team at [email protected].

API Reference

Constructs

Budget

Initializers

import { Budget } from 'cost-monitoring-construct'

new Budget(scope: Construct, id: string, props: IBudgetProps)
Name Type Description
scope constructs.Construct No description.
id string No description.
props IBudgetProps No description.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsRequired

Methods

Name Description
toString Returns a string representation of this construct.
clone create a copy of the object with the provided changes.

toString
public toString(): string

Returns a string representation of this construct.

clone
public clone(id: string, props: IOptionalBudgetProps): Budget

create a copy of the object with the provided changes.

idRequired
  • Type: string

a unique CDK Construct identifier.


propsRequired

you can choose to optionally pass all the initializer parameters of this class as the changes you wish to have on the cloned object.


Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { Budget } from 'cost-monitoring-construct'

Budget.isConstruct(x: any)

Checks if x is a construct.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


Classes

AccountCostMonitoring

Initializers

import { AccountCostMonitoring } from 'cost-monitoring-construct'

new AccountCostMonitoring(construct: Stack, props: IBudgetStrategyProps)
Name Type Description
construct aws-cdk-lib.Stack - use to define it's resources inside it.
props IBudgetStrategyProps No description.

constructRequired
  • Type: aws-cdk-lib.Stack

use to define it's resources inside it.


propsRequired

Methods

Name Description
createBudgets creates all the daily, monthly, quaryerly, and yearly budgets based on the implementation of the related methods.

createBudgets
public createBudgets(): void

creates all the daily, monthly, quaryerly, and yearly budgets based on the implementation of the related methods.

Properties

Name Type Description
dailyLimit number calculates daily limit based on the provided monthly limit.
monthlyLimit number returns montly limit.
quarterlyLimit number calculates quarterly limit based on the provided monthly limit.
yearlyLimit number calculates yearly limit based on the provided daily budget.
defaultTopic aws-cdk-lib.aws_sns.Topic Return default SNS topic only if the defultTopic prop has been passed when instantiating.

dailyLimitRequired
public readonly dailyLimit: number;
  • Type: number

calculates daily limit based on the provided monthly limit.


monthlyLimitRequired
public readonly monthlyLimit: number;
  • Type: number

returns montly limit.


quarterlyLimitRequired
public readonly quarterlyLimit: number;
  • Type: number

calculates quarterly limit based on the provided monthly limit.


yearlyLimitRequired
public readonly yearlyLimit: number;
  • Type: number

calculates yearly limit based on the provided daily budget.


defaultTopicOptional
public readonly defaultTopic: Topic;
  • Type: aws-cdk-lib.aws_sns.Topic

Return default SNS topic only if the defultTopic prop has been passed when instantiating.


ApplicationCostMonitoring

Initializers

import { ApplicationCostMonitoring } from 'cost-monitoring-construct'

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 ApplicationCostMonitoringProps No description.

stackRequired
  • Type: aws-cdk-lib.Stack

default stack to track its resources and it will be used to define Budget resources in it.


propsRequired

Methods

Name Description
createBudgets creates all the daily, monthly, quaryerly, and yearly budgets based on the implementation of the related methods.
monitor Creates all the alarms, budgets and tags all resources with the application's name.

createBudgets
public createBudgets(): void

creates all the daily, monthly, quaryerly, and yearly budgets based on the implementation of the related methods.

monitor
public monitor(): void

Creates all the alarms, budgets and tags all resources with the application's name.

Properties

Name Type Description
dailyLimit number calculates daily limit based on the provided monthly limit.
monthlyLimit number returns montly limit.
quarterlyLimit number calculates quarterly limit based on the provided monthly limit.
yearlyLimit number calculates yearly limit based on the provided daily budget.
defaultTopic aws-cdk-lib.aws_sns.Topic Return default SNS topic only if the defultTopic prop has been passed when instantiating.
applicationName string No description.

dailyLimitRequired
public readonly dailyLimit: number;
  • Type: number

calculates daily limit based on the provided monthly limit.


monthlyLimitRequired
public readonly monthlyLimit: number;
  • Type: number

returns montly limit.


quarterlyLimitRequired
public readonly quarterlyLimit: number;
  • Type: number

calculates quarterly limit based on the provided monthly limit.


yearlyLimitRequired
public readonly yearlyLimit: number;
  • Type: number

calculates yearly limit based on the provided daily budget.


defaultTopicOptional
public readonly defaultTopic: Topic;
  • Type: aws-cdk-lib.aws_sns.Topic

Return default SNS topic only if the defultTopic prop has been passed when instantiating.


applicationNameRequired
public readonly applicationName: string;
  • Type: string

ApplicationCostMonitoringProps

Initializers

import { ApplicationCostMonitoringProps } from 'cost-monitoring-construct'

new ApplicationCostMonitoringProps(applicationName: string, monthlyLimitInDollars: number, subscribers: string[], otherStacksIncludedInBudget?: Stack[], defaultTopic?: string, costAllocationTag?: string)
Name Type Description
applicationName string - the name of application to label resources with it.
monthlyLimitInDollars number - montly limit in US Dollors.
subscribers string[] - list of email address that the CostMonitoring will use to send alerts to.
otherStacksIncludedInBudget aws-cdk-lib.Stack[] - optional other stack to track their resources alog with the default stack.
defaultTopic string - default SNS topic name.
costAllocationTag string - Tag key used to track resources' expenditure.

applicationNameRequired
  • Type: string

the name of application to label resources with it.


monthlyLimitInDollarsRequired
  • Type: number

montly limit in US Dollors.


subscribersRequired
  • Type: string[]

list of email address that the CostMonitoring will use to send alerts to.


otherStacksIncludedInBudgetOptional
  • Type: aws-cdk-lib.Stack[]

optional other stack to track their resources alog with the default stack.


defaultTopicOptional
  • Type: string

default SNS topic name.

Only if provided, the BudgetStratgy creates an SNS topic and send notifications to it.


costAllocationTagOptional
  • Type: string

Tag key used to track resources' expenditure.

Only if provided, it will be used to tag the application resources. Defaults to cm:application


Properties

Name Type Description
applicationName string - the name of application to label resources with it.
monthlyLimitInDollars number - montly limit in US Dollors.
subscribers string[] - list of email address that the CostMonitoring will use to send alerts to.
costAllocationTag string - Tag key used to track resources' expenditure.
defaultTopic string - default SNS topic name.
otherStacksIncludedInBudget aws-cdk-lib.Stack[] - optional other stack to track their resources alog with the default stack.

applicationNameRequired
public readonly applicationName: string;
  • Type: string

the name of application to label resources with it.


monthlyLimitInDollarsRequired
public readonly monthlyLimitInDollars: number;
  • Type: number

montly limit in US Dollors.


subscribersRequired
public readonly subscribers: string[];
  • Type: string[]

list of email address that the CostMonitoring will use to send alerts to.


costAllocationTagOptional
public readonly costAllocationTag: string;
  • Type: string

Tag key used to track resources' expenditure.

Only if provided, it will be used to tag the application resources. Defaults to cm:application


defaultTopicOptional
public readonly defaultTopic: string;
  • Type: string

default SNS topic name.

Only if provided, the BudgetStratgy creates an SNS topic and send notifications to it.


otherStacksIncludedInBudgetOptional
public readonly otherStacksIncludedInBudget: Stack[];
  • Type: aws-cdk-lib.Stack[]

optional other stack to track their resources alog with the default stack.


IBudgetStrategy

Initializers

import { IBudgetStrategy } from 'cost-monitoring-construct'

new IBudgetStrategy(construct: Stack, props: IBudgetStrategyProps)
Name Type Description
construct aws-cdk-lib.Stack - use to define it's resources inside it.
props IBudgetStrategyProps No description.

constructRequired
  • Type: aws-cdk-lib.Stack

use to define it's resources inside it.


propsRequired

Methods

Name Description
createBudgets creates all the daily, monthly, quaryerly, and yearly budgets based on the implementation of the related methods.

createBudgets
public createBudgets(): void

creates all the daily, monthly, quaryerly, and yearly budgets based on the implementation of the related methods.

Properties

Name Type Description
dailyLimit number calculates daily limit based on the provided monthly limit.
monthlyLimit number returns montly limit.
quarterlyLimit number calculates quarterly limit based on the provided monthly limit.
yearlyLimit number calculates yearly limit based on the provided daily budget.
defaultTopic aws-cdk-lib.aws_sns.Topic Return default SNS topic only if the defultTopic prop has been passed when instantiating.

dailyLimitRequired
public readonly dailyLimit: number;
  • Type: number

calculates daily limit based on the provided monthly limit.


monthlyLimitRequired
public readonly monthlyLimit: number;
  • Type: number

returns montly limit.


quarterlyLimitRequired
public readonly quarterlyLimit: number;
  • Type: number

calculates quarterly limit based on the provided monthly limit.


yearlyLimitRequired
public readonly yearlyLimit: number;
  • Type: number

calculates yearly limit based on the provided daily budget.


defaultTopicOptional
public readonly defaultTopic: Topic;
  • Type: aws-cdk-lib.aws_sns.Topic

Return default SNS topic only if the defultTopic prop has been passed when instantiating.


Protocols

IApplicationCostMonitoringProps

Properties

Name Type Description
monthlyLimitInDollars number No description.
subscribers string[] No description.
defaultTopic string No description.
applicationName string No description.
costAllocationTag string No description.
otherStacksIncludedInBudget aws-cdk-lib.Stack[] No description.

monthlyLimitInDollarsRequired
public readonly monthlyLimitInDollars: number;
  • Type: number

subscribersRequired
public readonly subscribers: string[];
  • Type: string[]

defaultTopicOptional
public readonly defaultTopic: string;
  • Type: string

applicationNameRequired
public readonly applicationName: string;
  • Type: string

costAllocationTagOptional
public readonly costAllocationTag: string;
  • Type: string

otherStacksIncludedInBudgetOptional
public readonly otherStacksIncludedInBudget: Stack[];
  • Type: aws-cdk-lib.Stack[]

IBudgetAlertCondition

Properties

Name Type Description
period TimeUnit No description.
threshold number No description.
comparisonOperator ComparisonOperator No description.
notificationType NotificationType No description.
thresholdType ThresholdType No description.

periodRequired
public readonly period: TimeUnit;

thresholdRequired
public readonly threshold: number;
  • Type: number

comparisonOperatorOptional
public readonly comparisonOperator: ComparisonOperator;

notificationTypeOptional
public readonly notificationType: NotificationType;

thresholdTypeOptional
public readonly thresholdType: ThresholdType;

IBudgetProps

Properties

Name Type Description
alertContdition IBudgetAlertCondition No description.
limit number No description.
subscribers aws-cdk-lib.aws_budgets.CfnBudget.SubscriberProperty[] No description.
tags ITag[] No description.

alertContditionRequired
public readonly alertContdition: IBudgetAlertCondition;

limitRequired
public readonly limit: number;
  • Type: number

subscribersRequired
public readonly subscribers: SubscriberProperty[];
  • Type: aws-cdk-lib.aws_budgets.CfnBudget.SubscriberProperty[]

tagsOptional
public readonly tags: ITag[];

IBudgetStrategyProps

Properties

Name Type Description
monthlyLimitInDollars number No description.
subscribers string[] No description.
defaultTopic string No description.

monthlyLimitInDollarsRequired
public readonly monthlyLimitInDollars: number;
  • Type: number

subscribersRequired
public readonly subscribers: string[];
  • Type: string[]

defaultTopicOptional
public readonly defaultTopic: string;
  • Type: string

IOptionalBudgetAlertCondition

Properties

Name Type Description
comparisonOperator ComparisonOperator No description.
notificationType NotificationType No description.
period TimeUnit No description.
threshold number No description.
thresholdType ThresholdType No description.

comparisonOperatorOptional
public readonly comparisonOperator: ComparisonOperator;

notificationTypeOptional
public readonly notificationType: NotificationType;

periodOptional
public readonly period: TimeUnit;

thresholdOptional
public readonly threshold: number;
  • Type: number

thresholdTypeOptional
public readonly thresholdType: ThresholdType;

IOptionalBudgetProps

Properties

Name Type Description
alertContdition IOptionalBudgetAlertCondition No description.
limit number No description.
subscribers aws-cdk-lib.aws_budgets.CfnBudget.SubscriberProperty[] No description.
tags ITag[] No description.

alertContditionOptional
public readonly alertContdition: IOptionalBudgetAlertCondition;

limitOptional
public readonly limit: number;
  • Type: number

subscribersOptional
public readonly subscribers: SubscriberProperty[];
  • Type: aws-cdk-lib.aws_budgets.CfnBudget.SubscriberProperty[]

tagsOptional
public readonly tags: ITag[];

ITag

  • Implemented By: ITag

Properties

Name Type Description
key string No description.
value string | number No description.

keyRequired
public readonly key: string;
  • Type: string

valueRequired
public readonly value: string | number;
  • Type: string | number

Enums

ComparisonOperator

Members

Name Description
EQUAL_TO No description.
GREATER_THAN No description.
LESS_THAN No description.

EQUAL_TO

GREATER_THAN

LESS_THAN

NotificationType

Members

Name Description
ACTUAL No description.
FORECASTED No description.

ACTUAL

FORECASTED

SubscriptionType

Members

Name Description
EMAIL No description.
SNS No description.

EMAIL

SNS

ThresholdType

Members

Name Description
ABSOLUTE_VALUE No description.
PERCENTAGE No description.

ABSOLUTE_VALUE

PERCENTAGE

TimeUnit

Members

Name Description
DAILY No description.
MONTHLY No description.
QUARTERLY No description.
ANNUALLY No description.

DAILY

MONTHLY

QUARTERLY

ANNUALLY