top of page

Automate Retrieving your Azure Billing Data

Now I am not going to lie to you lovely reader, Microsoft Azure is not my strongest area when it comes to the Cloud. But I have been delving in, to find out more and make both our lives easier. Similar to my AWS Cost and Usage post, I wanted to find out more about the Azure bill.


I must say before we start that I only have exposure to an Azure setup with an Enterprise Agreement (EA), which means I get access to the billing data slightly differently to that of a normal account. To get info on singular azure accounts please look here.

For EA users we get the bill from the EA portal and it is called the ‘Usage Detail’.


Often, I find Azure to be …. Challenging and for this it was no different. I spent about a day looking online at different azure documentation pages which seemed to go around in circles. It took awhile for me to establish it was different for EA users, and seemed somewhat harder. I found node.js scripts, PowerShell from 2015, API options for different elements of the billing but nothing as simple as ‘Run this and get your report’. All I wanted was to be able to run a script that would download the Usage Detail into a CSV which I could then use for different concepts later and without me going into the EA portal to manually download it. This is also something I would have assumed to have been done before but it appeared I was in uncharted territory (sorry if you have written this script before but I legit could not find a working one!).


After all this searching I decided, if you want something done you gotta do it yourself and went about writing my own script. It turned out I only needed about 5 lines of python to get the job done 😹. Using requests I could get the usage report and download it to a CSV.

Getting that to work I wanted to make it a bit more flexible so I added some steps to allow for date selection. See the link here.


I am also adding this to my big tool I mentioned in another post, this runs the script as a lambda into an Athena table but keep an eye out for that later or message me if you would like a copy.


Usage Detail Breakdown


Now we have the CSV let’s take a closer look at it. Similar to the AWS report I have the 5 W’s for the Usage Detail too:


What the costs are = Cost

Who used it = you can either use AccountName/SubscriptionName/SubscriptionGuid Depending on how you split your accounts bills

When did you use it = Date

Where in the world = ResourceLocation

Why you spent the money = Product


For the full details see Azures documentation.

With the basics covered you can get your Azure bill in an automated fashion and start exploring it.

 
 
 

Comments


  • twitter
  • linkedin
  • generic-social-link

©2019 by Road to FinOps. Proudly created with Wix.com

bottom of page