Code Monkey home page Code Monkey logo

aws-cost-explorer's Introduction

aws-cost-explorer

Simple AWS Cost Explorer API Implementation for Node.js

Installation

npm install aws-cost-explorer

AWS Account Configuration

This module requires an AWS Key Pair and access to AWS Cost Explorer API (ce). Example policy to attach:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ce:*"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}

source : Billing And Cost Management Example 12

Usage

var CostExplorer = require('aws-cost-explorer');
var ce = CostExplorer();

ce.getMonthToDateCosts(null, function(err, data) {
    if (err) {
        console.log(err);
    } else {
        console.dir(data, { depth: null });
    }
});

Passing AWS Configuration Options

var config = { 
    apiVersion: '2017-10-25',
    accessKeyId : 'AKIAJVCSKEY3SAMPLE',
    secretAccessKey : 'yWKUsVwtaXnssdGBeEVGPSAMPLE9hZuz9SAMPLE',
    region : 'us-east-1'
}

var CostExplorer = require('aws-cost-explorer');
var ce = CostExplorer(config);

ce.getMonthToDateCosts(null, function(err, data) {
    if (err) {
        console.log(err);
    } else {
        console.dir(data, { depth: null });
    }
});

Automatic Configuration from /config/default.json file

aws-cost-explorer uses config module to automatically load aws config keys an values from _dirname/config folder

var CostExplorer = require('aws-cost-explorer');
var ce = CostExplorer();

ce.getMonthToDateCosts(null, function(err, data) {
    if (err) {
        console.log(err);
    } else {
        console.dir(data, { depth: null });
    }
});

Sample default.json file located in _dirname/config folder

{
    "AWS": {
        "CostExplorer" : {
            "apiVersion" : "2017-10-25",
            "accessKeyId" : "AKIAJV1111SSDDDY73NTTEBVXQ",
            "secretAccessKey" : "yWKUsVwtaXnASDqwe1232312L9DI9hZuz9Gp6cEXB",
            "region" : "us-east-1"
        }

    }
}

Available Methods

getMonthToDateCosts(opts, callback)

getTodayCosts(opts, callback)

getLastMonthCosts(opts, callback)

getYearToDateCosts(opts, callback)

getTags(opts, callback)

getCostForADay(date, opts, callback)

Parameters

opts (optional)

opts = {
    granularity : "MONTHLY" | "DAILY" | "HOURLY",
    metrics : "BlendedCost" | "UnblendedCost",
    groupBy : [
      {
        'Type': 'TAG',
        'Key': 'MyTagName' 
      }
    ]
}

Response Data

{
	ResultsByTime: [{
		TimePeriod: {
			Start: '2017-11-01',
			End: '2017-11-30'
		},
		Total: {
			BlendedCost: {
				Amount: '4066.1336704447',
				Unit: 'USD'
			}
		},
		Groups: [],
		Estimated: false
	}],
    Total: {
        Amount: 4066, 
        Unit: 'USD'
    }
}

Tests

npm tests

Examples

Changelog

  • 0.1.3
    • Add GetCost filtering using timeframes
    • Examples
    • Doc
    • Dependency problems fixed
  • 0.1.2
    • Add GetTags method support
    • Update reference to Grafana Backend Demo
  • 0.1.1
    • First Release

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.