Skip to content

Latest commit

 

History

History
57 lines (38 loc) · 2.41 KB

ec2.md

File metadata and controls

57 lines (38 loc) · 2.41 KB

AWS Lambda

Note

Max AWS EC2 instances spending rate with default AWS Quotas: $63 / hour / region

Usage

Preferred implementation leverages CostLimit aspect.

Alternatively, you can simply replace your Instance native CDK import statement by this package exported Instance construct.

- import { Instance } from "@aws-cdk-lib/aws-ec2";
+ import { Instance } from "@revant-io/cdk-cost-limit";

The Instance construct accepts the exact same props at the AWS CDK Instance construct (refer to the AWS CDK dedicated documentation for a list of all supported props). In addition to those native props, it accepts the following:

Name Type Description
budget? number The monthly budget limit for this specific resource, specified in $US cents

Example

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

const fn = new Instance(this, "MyInstance", {
  /* The budget allocated to this resource in $US cents.
   * For exemple, if you want to set a budget of $1,00
   * for a specific Lambda function, you should used
   * a value of 100 for this prop.
   */
  budget: 100,
});

By default, if budget is not specified, an unlimited budget (Instance normal behavior) is used.

How it works

EC2 architecture

Disabling strategy

EC2 instances are disabled using the StopInstances command.

What is deployed?

EC2 service nativelly broadcast status update event on AWS account default EventBridge Bus. 2 EventBridge Rules are provisionned to listen to instance-specific starting and stopping events. Those rules targets a generic lambda function in charge of fetching up-to-date catalog price for the instance, updating incurred expenses rate, and eventually stop the instance if budget is already exceeded. Budget informations (address and amout) are accessible by the lambda through parameters specified directly on the rule.

Manually restore

In order to reset Instance that have been disabled by a budget, you need to start the instance.

aws ec2 start-instances --instance-ids <instanceId>