Simple AWS Cost Explorer API Implementation for Node.js
npm install aws-cost-explorer
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
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 });
}
});
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 });
}
});
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"
}
}
}
opts = {
granularity : "MONTHLY" | "DAILY" | "HOURLY",
metrics : "BlendedCost" | "UnblendedCost",
groupBy : [
{
'Type': 'TAG',
'Key': 'MyTagName'
}
]
}
{
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'
}
}
npm tests
-
Check Example folder
-
Rest API using Express
- 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