UNPKG

@cloud-carbon-footprint/aws

Version:

The core logic to get cloud usage data and estimate energy and carbon emissions from Amazon Web Services.

55 lines 2.86 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const common_1 = require("@cloud-carbon-footprint/common"); const ComputeOptimizerRecommendationWithProcessors_1 = __importDefault(require("./ComputeOptimizerRecommendationWithProcessors")); const core_1 = require("@cloud-carbon-footprint/core"); class LambdaTargetComputeOptimizerRecommendation extends ComputeOptimizerRecommendationWithProcessors_1.default { constructor(computeOptimizerRecommendationData) { super(computeOptimizerRecommendationData); this.accountName = this.accountId; this.region = this.getRegion(computeOptimizerRecommendationData.functionArn); this.recommendationOptions = [ { memorySize: computeOptimizerRecommendationData.recommendationOptions_1_configuration_memorySize, costSavings: computeOptimizerRecommendationData.recommendationOptions_1_estimatedMonthlySavings_value, }, { memorySize: computeOptimizerRecommendationData.recommendationOptions_2_configuration_memorySize, costSavings: computeOptimizerRecommendationData.recommendationOptions_2_estimatedMonthlySavings_value, }, { memorySize: computeOptimizerRecommendationData.recommendationOptions_3_configuration_memorySize, costSavings: computeOptimizerRecommendationData.recommendationOptions_3_estimatedMonthlySavings_value, }, ]; const optimalRecommendation = this .recommendationOptions[0]; this.resourceId = this.getResourceId(computeOptimizerRecommendationData.functionArn); this.memorySize = optimalRecommendation.memorySize; this.description = `${this.memorySize}MB`; this.vCpus = this.getVcpusForLambda(this.memorySize); this.costSavings = parseFloat(optimalRecommendation.costSavings); this.vCpuHours = this.getVCpuHours(this.vCpus); this.usageAmount = (0, common_1.getHoursInMonth)(); } getResourceId(functionArn) { const functionData = functionArn.split(':'); const name = functionData[functionData.length - 2]; const version = functionData[functionData.length - 1]; return `${name}:${version}`; } getVcpusForLambda(memorySize) { return (parseFloat(memorySize) / 1769).toString(); } getComputeProcessors() { return [core_1.COMPUTE_PROCESSOR_TYPES.UNKNOWN]; } getGPUComputeProcessors() { return [core_1.COMPUTE_PROCESSOR_TYPES.UNKNOWN]; } } exports.default = LambdaTargetComputeOptimizerRecommendation; //# sourceMappingURL=LambdaTargetComputeOptimizerRecommendation.js.map