Stage 5 · Platform
Azure Foundations
Cost Management & FinOps
Budgets, alerts, reservations, spot VMs, and reading your billing invoice.
Understanding Azure Costs
Azure costs fall into three categories: compute (VMs, AKS, App Services), storage (blobs, disks, files), and networking (data transfer, load balancers, VPN gateways). The largest cost driver is almost always compute.
- Compute — Pay per second for VMs, per vCPU-hour for AKS nodes, per request for serverless
- Storage — Pay per GB/month for capacity, plus per-GB charges for transactions and egress
- Networking — Inbound traffic is free; outbound traffic (egress) is charged per GB
- Other — Key Vault operations, DNS queries, support plans, and marketplace licenses
Data egress (outbound data transfer) between Azure regions or from Azure to the internet is charged. Cross-region traffic costs $0.02-0.08/GB depending on regions. Keep data gravity in mind when designing architectures.
Cost Management + Billing
Cost Management + Billing is Azure's built-in tool for analyzing, managing, and optimizing cloud costs. It provides spending dashboards, cost analysis by tags, and export capabilities for external reporting.
# List costs for the current month by resource group
az cost management query \
--type Usage \
--time-period from=2025-01-01 to=2025-01-31 \
--group-by resourceGroup \
--query "value[].{group:name, cost:preTaxCost}" \
--output table
# List costs by tag
az cost management query \
--type Usage \
--time-period from=2025-01-01 to=2025-01-31 \
--group-by tag.Environment \
--query "value[].{env:name, cost:preTaxCost}" \
--output tableThe Cost Management API provides detailed cost breakdowns. Use tag-based grouping to allocate costs to teams, projects, or environments.
Budgets and Alerts
Azure Budgets let you set spending thresholds and trigger alerts when costs exceed defined limits. Alerts can notify via email, call webhooks, or trigger automation runbooks.
# Create a budget for a resource group
az consumption budget create \
--amount 5000 \
--category cost \
--resource-group rg-payments-prod \
--name "Monthly Budget - Payments Prod" \
--start-date 2025-01-01 \
--end-date 2025-12-31 \
--time-grain monthly \
--thresholds 80 100The --thresholds flag sets alert percentages. In this example, alerts fire at 80% (warning) and 100% (critical) of the $5,000 budget.
# Create an action group for budget alerts
az monitor action-group create \
--resource-group rg-shared \
--name ag-cost-alerts \
--short-name costalerts \
--action email admin-team admin@contoso.com
# Reference the action group when creating a budget
az consumption budget create \
--amount 10000 \
--resource-group rg-prod \
--name "Annual Budget" \
--start-date 2025-01-01 \
--end-date 2025-12-31 \
--action-group "/subscriptions/{sub-id}/resourceGroups/rg-shared/providers/microsoft.insights/actionGroups/ag-cost-alerts" \
--thresholds 50 75 90 100Action groups can trigger emails, SMS, push notifications, Azure Functions, Logic Apps, or webhook calls. Use them to automate responses to budget alerts.
Reservations and Savings Plans
Reservations provide significant discounts (up to 72%) in exchange for committing to 1 or 3 years of a specific resource type. Azure Savings Plans offer similar discounts with more flexibility across VM families and regions.
| Commitment | Discount | Flexibility | Best For |
|---|---|---|---|
| Pay-as-you-go | 0% | Full | Dev/test, unknown workloads |
| 1-year reservation | Up to 40% | Within resource type | Stable, predictable workloads |
| 3-year reservation | Up to 65% | Within resource type | Long-term production |
| Savings Plan | Up to 72% | Across VM families/regions | Flexible production workloads |
Spot Virtual Machines
Spot VMs use Azure's unused capacity at deeply discounted prices (up to 90% off). The trade-off is that Azure can evict them with 30 seconds notice when capacity is needed. Spot VMs are ideal for batch processing, dev/test, and fault-tolerant workloads.
# Create a spot VM for batch processing
az vm create \
--resource-group rg-batch \
--name vm-batch-spot \
--image Ubuntu2204 \
--size Standard_D4s_v3 \
--priority Spot \
--eviction-policy Deallocate \
--max-price -1 \
--admin-username azureuser \
--generate-ssh-keys--max-price -1 means you will pay up to the pay-as-you-go price. You can set a specific max price to cap your spend. --eviction-policy Deallocate pauses the VM instead of deleting it.
Spot VMs can be evicted at any time. Never run stateful, stateful, or latency-sensitive workloads on spot capacity. Use them for stateless batch jobs, CI/CD agents, or dev environments only.
Cost Optimization Practices
Cost optimization is an ongoing process, not a one-time task. These practices help you continuously reduce and control Azure spending.
- Right-size VMs — Use Azure Advisor to identify underutilized VMs and resize them
- Auto-shutdown dev VMs — Schedule dev/test VMs to shut down outside business hours
- Use reservations for steady-state — Commit to 1 or 3 year reservations for production workloads
- Use spot for batch — Run fault-tolerant workloads on spot VMs for up to 90% savings
- Delete unused resources — Remove idle NICs, unattached disks, and orphaned public IPs
- Monitor egress — Keep data gravity in mind and minimize cross-region transfers
# List VMs with low CPU utilization
az advisor recommendation list \
--category Cost \
--query "[?impact=='High'].{title:shortDescription.problem, resource:resourceMetadata.resourceId}" \
--output table
# List unattached managed disks (common waste)
az disk list \
--query "[?managedBy==null].{name:name, size:diskSizeGb, tier:sku.name}" \
--output tableAzure Advisor analyzes your usage patterns and provides personalized recommendations. The Cost category specifically identifies underutilized resources and savings opportunities.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.