javascriptnode.jsamazon-web-servicesaws-billing

AWS monthly billing service charges nodejs


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


Solution

  • 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', },