Giter VIP home page Giter VIP logo

aws-cost-explorer's People

Contributors

coulonxyz avatar dnavarrom avatar palmerabollo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

aws-cost-explorer's Issues

Allow to get cost for a specific day

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);
}

Add Code Examples

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:

Grouping by Service

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.