0

I am trying to get the monthly billing data for an AWS production account through a nodejs script.

const getbillingReport = () => {


        getcreds({ accountId: '1234554321', region:'us-east-1'})
        .then(accCreds => {
        costexplorer = new AWS.CostExplorer(accCreds);

        var params = {
        Metrics: [ 
        'BlendedCost',
        ],
        TimePeriod: { 
            End:'2022-02-28',
            Start: '2022-02-01',
        },
        Granularity: 'MONTHLY',
        
        };

        costexplorer.getCostAndUsage(params, function(err, data) {
            if (err) console.log(err, err.stack);
            else     console.log(JSON.stringify(data));    


        })
    });

The amount that I get by running the query is different from the actual Amazon Web Services, Service Charges that I see when I navigate to the Billing Dashboard --> Bills and choose a month(February 2022). Could someone guide me on the changes I should make on the query to get the exact amount that I see in the billing dashboard

raosa
  • 119
  • 1
  • 8
  • Just wondering why your time period starts from 2022-01-31? Does it work as expected if you start from 2022-02-01? – Register Sole Mar 21 '22 at 03:34
  • Hi, I have updated the date to be '2022-02-01'. The amount that the getCostAndUsage returns and the one that I see within the billing dashboard is still different. My guess is that instead of Metrics: [ 'BlendedCost', ] , should I be using any other parameter to get the actual Amazon Web Services, Service Charges? – raosa Mar 21 '22 at 15:41
  • Oh true, seems you should use unblended cost as per [this article](https://aws.amazon.com/blogs/aws-cloud-financial-management/understanding-your-aws-cost-datasets-a-cheat-sheet/), as this is the dataset displayed on the Bills page. As bonus, it also explains amortized and blended costs. Let me know if this works! – Register Sole Mar 22 '22 at 02:50

1 Answers1

0

The aws documentation states that the End in TimePeriod is exclusive in nature. So I had to modify the params list to be March 1st so that the billing information for 28 Feb is also included. i.e. TimePeriod: { End:'2022-03-01', Start: '2022-02-01', },

raosa
  • 119
  • 1
  • 8