Overview and What You Will Learn
In this lab, you will check current subscription spend using the CLI, create a budget with an alert threshold, and understand exactly what triggers Azure to notify you before a bill grows larger than expected.
Why This Matters in Production
A developer at a startup spins up a test environment on a free trial account, forgets about it, and returns three weeks later to find the entire trial credit consumed by a VM that was never actually used after the first day. A budget alert set on day one would have flagged this well before the credit ran out, turning a silent surprise into an early, actionable warning.
Core Principles
Azure's core billing model is consumption-based - you are charged for what you actually use, not a pre-purchased fixed amount, though Reserved Instances and Savings Plans exist separately for predictable workloads at a discount.
+------------------------------------------+| Resource created (VM, Storage, etc.) |+------------------------------------------+ | v+------------------------------------------+| Azure creates a usage Meter for it |+------------------------------------------+ | v+------------------------------------------+| Meter usage tracked continuously |+------------------------------------------+ | v+------------------------------------------+| Budget compares actual spend to threshold || Alert fires once threshold is crossed |+------------------------------------------+A Budget is a defined spending limit over a time period. It does not stop spending on its own - it triggers an alert (email, or an action like notifying a webhook) once actual or forecasted spend crosses a percentage of that limit you configure.
Detailed Step-by-Step Practical Lab
- Check current month-to-date usage for your subscription:
az consumption usage list --output table- Create a budget with an alert configured to fire at 80% of the limit - this example uses the Portal path since Budgets are most commonly configured there, but the underlying concept applies identically via CLI or ARM template:
Portal: Cost Management + Billing -> Budgets -> + Add Scope: your subscription Amount: 2000 (INR, or your currency) Reset period: Monthly Alert condition: Actual, 80% of budgeted amount Alert recipient: your email address- Use the Pricing Calculator to estimate cost for a specific configuration before deploying it for real:
Go to azure.microsoft.com/pricing/calculatorSelect: Virtual MachinesConfigure: Region = Central India, Size = B2s, OS = UbuntuReview the estimated monthly cost before creating anything- Check Azure Advisor's cost recommendations for any resources you already have deployed:
az advisor recommendation list \ --category Cost \ --output tableNoteAdvisor recommendations only appear after a resource has generated enough usage history for Azure to analyze - a brand-new VM created minutes ago will not yet have a rightsizing recommendation.
- If any recommendation suggests downsizing an underused resource, review it and apply the change if it fits your actual usage pattern.
Production Best Practices & Common Pitfalls
Common MistakeCreating a free trial or pay-as-you-go account and deploying test resources without ever setting a budget alert. A single oversized VM or an unexpectedly popular test workload can consume far more than expected before anyone notices, since nothing was watching for it.
TipSet a budget alert at 80% of whatever limit matters to you - your trial credit, or a monthly departmental cap - rather than waiting until 100% is reached. An 80% alert gives you time to actually react; a 100% alert often means the spend has already happened.
- Region choice affects price for identical resources. The same VM size can cost meaningfully more or less depending on which region it's deployed in - always check pricing for your actual target region, not just whichever region the calculator defaults to.
- Auto-shutdown is the single easiest cost win for dev/test VMs. A VM that only needs to run during business hours but stays on 24/7 is paying for roughly two-thirds of its runtime for nothing.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
az consumption usage list |
List current usage and cost for the subscription |
az advisor recommendation list --category Cost |
List cost-saving recommendations |
az consumption budget list |
List existing budgets on the subscription |