UNPKG

@cloud-carbon-footprint/aws

Version:

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

38 lines 1.96 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const aws_sdk_1 = require("aws-sdk"); const common_1 = require("@cloud-carbon-footprint/common"); const GCPCredentials_1 = __importDefault(require("./GCPCredentials")); class AWSCredentialsProvider { static create(accountId) { switch ((0, common_1.configLoader)().AWS.authentication.mode) { case 'GCP': return new GCPCredentials_1.default(accountId, (0, common_1.configLoader)().AWS.authentication.options.targetRoleName, (0, common_1.configLoader)().AWS.authentication.options.proxyAccountId, (0, common_1.configLoader)().AWS.authentication.options.proxyRoleName); case 'AWS': const partition = (0, common_1.configLoader)().AWS.IS_AWS_GLOBAL ? `aws` : `aws-cn`; return new aws_sdk_1.ChainableTemporaryCredentials({ params: { RoleArn: `arn:${partition}:iam::${accountId}:role/${(0, common_1.configLoader)().AWS.authentication.options.targetRoleName}`, RoleSessionName: (0, common_1.configLoader)().AWS.authentication.options.targetRoleName, }, }); case 'EC2-METADATA': return new aws_sdk_1.EC2MetadataCredentials({ httpOptions: { timeout: 5000 }, maxRetries: 10, }); case 'ECS-METADATA': return new aws_sdk_1.ECSCredentials({ httpOptions: { timeout: 5000 }, maxRetries: 10, }); default: return new aws_sdk_1.Credentials(aws_sdk_1.config.credentials); } } } exports.default = AWSCredentialsProvider; //# sourceMappingURL=AWSCredentialsProvider.js.map