dnavarrom / aws-cost-explorer Goto Github PK
View Code? Open in Web Editor NEWSimple AWS Cost Explorer API Implementation
License: MIT License
Simple AWS Cost Explorer API Implementation
License: MIT License
I tried to push a PR but I don't have the rights.
Here is the code:
/**
* @func getCostForADay
* @desc Get cost for a specific day
* @param {Date} date of the costs
* @param {Object} opts Option object
* @param {string} [opts.metrics = BlendedCosts] Metric Alternatives "BlendedCost | UnblendedCost"
* @param {string} [opts.granularity = MONTHLY] Alternatives "MONTHLY | DAILY | HOURLY"
* @param {string} [opts.groupBy = null] used to group by tags example : opts.groupBy = [ { 'Type' : 'TAG', 'Key' : 'MyTagName'}]
* @param {callback} Callback function
*/
method.getCostForADay = function (date, opts, callback) {
if (hasConfigError) {
console.log("ERROR : Invalid configuration loaded");
return callback("ERROR : Invalid configuration loaded", null);
}
var StartDate = moment(date).format('YYYY-MM-DD');
var EndDate = moment(date).add(1, 'd').format('YYYY-MM-DD');
var metrics = opts && opts.metrics ? opts.metrics : "BlendedCost";
var granularity = opts && opts.granularity ? opts.granularity : "DAILY";
var groupBy = opts && opts.groupBy ? opts.groupBy : null;
var costParams = {
TimePeriod: {
End: EndDate,
/* required */
Start: StartDate /* required */
},
Granularity: granularity,
Metrics: [metrics],
GroupBy: groupBy
}
awsCostExplorer.getCostAndUsage(costParams, function (err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
return callback(err, null);
} else {
return callback(null, getAggregatedCosts(data, metrics));
}
});
}
/**
* @func getTodayCosts
* @desc Get TodayCosts
* @param {Object} opts Option object
* @param {string} [opts.metrics = BlendedCosts] Metric Alternatives "BlendedCost | UnblendedCost"
* @param {string} [opts.granularity = MONTHLY] Alternatives "MONTHLY | DAILY | HOURLY"
* @param {string} [opts.groupBy = null] used to group by tags example : opts.groupBy = [ { 'Type' : 'TAG', 'Key' : 'MyTagName'}]
* @param {callback} Callback function
*/
method.getTodayCosts = function (opts, callback) {
return method.getCostForADay(new Date(), opts, callback);
}
Type of issue
Bug
Idea/Suggestion
Question
Description (include any screenshots or debugging information if applicable)
Provide examples to implement filters and options from AWS Cost Explorer Documentation to save developer time providing specific usage scenarios (which is the primary purpose of this library). Steps:
Sorry if this is documented somewhere and I just can't find it, but I don't see how to group by service currently. Mainly I'm unsure what to pass as the Key
, assuming I can set the Type
to SERVICE
.
Any assistance appreciated!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.