@cloud-carbon-footprint/aws
Version:
The core logic to get cloud usage data and estimate energy and carbon emissions from Amazon Web Services.
41 lines • 1.87 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const credential_providers_1 = require("@aws-sdk/credential-providers");
const common_1 = require("@cloud-carbon-footprint/common");
const GCPCredentials_1 = __importDefault(require("./GCPCredentials"));
class AWSCredentialsProvider {
static create(accountId) {
const auth = (0, common_1.configLoader)().AWS.authentication;
switch (auth.mode) {
case 'GCP':
return new GCPCredentials_1.default(accountId, auth.options.targetRoleName, auth.options.proxyAccountId, auth.options.proxyRoleName).getProvider();
case 'AWS': {
const partition = (0, common_1.configLoader)().AWS.IS_AWS_GLOBAL ? 'aws' : 'aws-cn';
const roleName = auth.options.targetRoleName;
return (0, credential_providers_1.fromTemporaryCredentials)({
params: {
RoleArn: `arn:${partition}:iam::${accountId}:role/${roleName}`,
RoleSessionName: roleName,
},
});
}
case 'EC2-METADATA':
return (0, credential_providers_1.fromInstanceMetadata)({
timeout: 5000,
maxRetries: 10,
});
case 'ECS-METADATA':
return (0, credential_providers_1.fromContainerMetadata)({
timeout: 5000,
maxRetries: 10,
});
default:
return (0, credential_providers_1.fromNodeProviderChain)();
}
}
}
exports.default = AWSCredentialsProvider;
//# sourceMappingURL=AWSCredentialsProvider.js.map