简体   繁体   中英

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

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. ie TimePeriod: { End:'2022-03-01', Start: '2022-02-01', },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM