How I keep costs in check for my Azure subscription

I am very privileged to get an Azure subscription at my disposal. This does however come with some responsibilities, as (even inside of Microsoft) Azure costs are cross-charged. So I try to keep my bill minimal.
I wanted to share some of my own best practices to keep costs under control in my personal testing subscription.

Stopping machines

I experiment a lot with VMs. Those get charged per minute, and every minute they are shutdown –  is a minute spent less. But if you are like me, you’ll often forget to stop your VMs; and the meter will continue to run.
There are a couple of ways to automate the stopping (and if you want, the starting) of VMs:

  1. Using Azure Devtests labs, which comes with a timer for start/stop built-in.
  2. Using the VM portal blade.
  3. Using Azure Automation.

I personally use the third option. The reason behind this is that the schedule is a bit more flexible for when I’m doing tests past the shutdown time: Within my automation account, I have a schedule that automatically shuts down all my machines at 7PM. However, I sometimes work after 7PM; and will configure a schedule on my automation account to ‘one-off’ shutdown my machines at midnight (I rarely work past midnight). You’ll see an example from two days ago below:
I use the built-in Azure Automation shutdown script to achieve this. It allows you to specify subscription level – resource group level or individual VM level control about what you shut down. As all my VMs are simply demo’s – I shutdown everything in my subscription.

Cleaning up after myself

Virtual machines aren’t the only elements that drive up cost. If you create and delete VMs quiet often – the cost for storage can also add up. And when you delete a VM, the attached disk isn’t automatically deleted with it.
Also using Azure Automation, I clean up my unattached disks (and NICs, but they are free) every night. If you’re interested in the script itself, I made that available on my Github page.

Choosing the right VM sizes

I promise I’ll stop talking about VMs after this one. Picking the right size of VM might also keep your costs down. Even if you shut them down every night, the difference between an A1 and a G5 is still about 8.5$ per hour. In all honesty, I haven’t done tests myself with a G5, but I have played around with some F72s_v2 machines for some large tests.
My go-to size nowadays is either the B1/B2 VM or the D2_v3. I’ll pick the B series if I don’t plan to do too much with the machines – I’ll pick the Dv3 series if I plan to stress the machines. The B series are burstable machines, meaning they won’t give you full CPU power all the time. But even if I do some light development work in VS; I sometimes even use the B-series. I find attaching a premium disk helps a lot more with performance than the full CPU power.

Grouping resources for easy deletion

As I do a lot of demos and tests, I tend to throw away a lot of resources. Just earlier today, I was playing around with Service Fabric Mesh – and after my test (which took about 1 hour) I just threw the resource away.
Now, SF Mesh was just 1 resource. If you play around with more complex systems; grouping them together in resource groups really helps. I create a resource group per test, which I can easily discard when needed.
I could take this one step further even – and tag my resource groups for demo/deletion time. If I have a “deleteBy” tag, I could run an automation script that deletes the resource group by a certain day. But, I don’t have that today.

Go for the free/basic/shared plan when available – but remember that choice when things don’t work

Multiple Azure services have a free or basic plan. Think about App Service, Cognitive services, IoT Hub, Functions… If you can get it for free, why not take it for free. Troy Hunt even runs Pwned Passwords on Free Azure Functions.
This recommendation however comes with a caveat: not all features all available in the free and basic offerings. This one came back like a boomerang to me yesterday. I was playing around with an IoT Devkit, and wanted to connect that to IoT Hub (follow this series of Tweets to share in my excitement). I started out with a basic IoT Hub, and apperently the demo code from the DevKit didn’t play nice with a basic IoT Hub. I couldn’t connect my device – I upgraded the IoT hub to a standard – et voila, everything worked fine.


I quickly wanted to share how I optimize my own Azure spend. My steady state spend is about 100$, plus any larger tests I do. My largest bill until now was about 2k$ for a month. This was when I discovered a bug in the (then) new VPNGW3 SKU; and support asked me to keep them running.
Do you have any special tricks you use to keep spend under control?

One thought to “How I keep costs in check for my Azure subscription”

Leave a Reply