npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@revant-io/cdk-cost-limit

v0.2.0

Published

<!-- HEADER --> <br /> <div align="center"> <a href="https://github.com/revant-io"> <img src="images/logo.png" alt="Logo" width="80" height="80"> </a>

Downloads

13

Readme

Overview

What?

This package lets you set spending limits on AWS. While existing AWS solutions merely alert, this library disables resources, using non-destructive operations, when budgets are hit.

Why?

Every month, companies and individual contributors face surging cloud bills[^1] due to mistakes in their application code, misunderstandings of services pricing model, or even malicious activities. This library shields you from such events.

How?

This library includes an Aspect and a collection of AWS CDK Level-2 Constructs. They deploy additional resources to compute real-time spending and halt resources when budgets are met (e.g. Lambda Functions reserved concurrency is set to 0)

Tradeoffs

  • 🚧 Availability - Disabled resources impacts your application availability
  • 💰 Costs - Tracking spending and halting resources incur additional costs
  • 🏎️ Performance - Some implementations negatively impact performances

[!IMPORTANT] 🧑‍💻 We're actively working on reducing cost and perf impacts of this library! We'll keep you posted as we minimize and eventually remove complitely those tradeoffs

Getting started

Prerequisites

  • CDK >= 2 - only applications deployed using AWS CDK can use this library. It is not a standalone application.
  • Node.js >= 14.15.0 - even those working in languages other than TypeScript or JavaScript (see AWS CDK Documentation)

Installation

npm install -s @revant-io/cdk-cost-limit

Usage guide

Using this library is as simple as importing the CostLimit Aspect and using it on any node to apply a budget on the node and all of its children.

import { Aspects } from "aws-cdk-lib";
import { CostLimit } from "@revant-io/cdk-cost-limit";

Aspects.of(anyConstruct).add(new CostLimit({ budget: 1000 }))

Using an aspect allow setting a budget on a specific construct of the application, or even a whole stack. Multiple budgets can be set up at once.

import { App, Aspects, Stack } from "aws-cdk-lib";
import { Instance } from "aws-cdk-lib/aws-ec2";
import { Function } from "aws-cdk-lib/aws-lambda";

import { CostLimit } from "@revant-io/cdk-cost-limit";

const app = new App();
const stack = new Stack(app, "MyStack");

const myEC2Instance = new Instance(stack, "MyEC2Instance");
const myFirstLambdaFunction = new Function(stack, "MyFirstLambda");
const mySecondLambdaFunction = new Function(stack, "MySecondLambda");

// Sets one global budget on all resources within MyStack of $10,00
Aspects.of(stack).add(new CostLimit({ budget: 1000 }));

// Sets another budget on MyFirstLambda of $2,00
Aspects.of(myFirstLambdaFunction).add(new CostLimit({ budget: 200 }));

// Sets a final budget on MySecondLambda of $5,00
Aspects.of(mySecondLambdaFunction).add(new CostLimit({ budget: 500 }));

Once a budget is hit, all resources within the construct on which this budget has been applied are disabled to prevent further cost increase. In the above example:

  • once MyFirstLambda incurred costs reach $2,00, the lambda function is disabled
  • once MySecondLambda incurred costs reach $5,00, the lambda function is disabled
  • once MyStack incurred costs reach $10,00 - in this specific case, the addition of incurred costs from MyEC2Instance, MyFirstLambda and MySecondLambda - all resources within MyStack are disabled

Supported services/resources

While CostLimit aspect can be applied on any node type, budget capabilities are only enabled on a subset of resources listed below. Cost generated by resources other than the one specified are not taken into account with regards to the budget limit. Only resources listed below are disabled once budget is reached.

Lifecycle

  • 🧑‍💻 Develop - Use this library to set your budget limit. Look at the catalog documentation to learn how to implement a budget. You can update budget amount and location anytime.

  • 🤖 Limit - Budgeted resources will disable automatically when budget is reached. Have a look at each service documentation to understand how resource are disabled.

  • 🔄 Restore

    • 📆 Automatically - At the end of each month, resources that have been disabled are automatically re-enabled

    • ⚒️ Manually - You might want to increase budget and keep on using disabled resources in the current month. In order to do so, you need to follow each service documentation procedure to identify and manually re-enable affected resources

[^1]: 📖 Have a look at those AWS billing horror stories aggregated by Victor Grenu!