Set a budget, read what Advisor recommends, and add a lifecycle rule that trims storage spend automatically.
Cost is an engineering control, not a report
The junior version of cost management is looking at last month's bill and wincing. The engineering version is putting mechanisms in place so the bill cannot surprise you and waste cannot accumulate quietly. Azure gives you three that a cloud engineer is expected to wield: budgets that raise an alert when spend crosses a threshold — before the month closes, not after; Azure Advisor, which continuously inspects your resources and recommends right-sizing and idle-resource cleanup; and storage lifecycle policies, which move cooling data to cheaper tiers and delete it on a schedule without anyone remembering to. This lab sets all three from the command line, so cost control becomes something you deploy, like any other infrastructure.
None of these guardrails costs anything to create — they are governance features, not resources. The only thing you make that could bill is an empty storage account, and empty storage is free.
You cannot optimise a bill after it arrives. You engineer the guardrails before it does.
You need a free Azure account, the Azure CLI (az), then be signed in with az login. First time? The 15-minute Set up your machine page covers the account, the installs (winget / brew / apt), and sign-in. Prefer zero installs? Run everything in Azure Cloud Shell (Bash), preinstalled and already signed in.
This page walks the whole lab; the budget and lifecycle JSON are in github.com/kloudcaptain/campux-labs under lab-cost-guardrails. Run everything in Azure Cloud Shell (Bash). Put your own email in the budget notification so the alert would actually reach you.
A group to scope the budget to
# Windows/Git Bash: stop it mangling /subscriptions/... arguments (harmless on macOS/Linux)
export MSYS_NO_PATHCONV=1
RG="campux-lab-cost-rg"
az group create -n "$RG" -l eastus
A budget that warns you at 80%
Create a monthly budget scoped to the group, with a notification that emails you when actual spend reaches 80% of the amount. The start date must be the first of a month.
START=$(date -u +%Y-%m-01)
az consumption budget create-with-rg \
--budget-name campux-monthly \
--resource-group "$RG" \
--amount 50 \
--category Cost \
--time-grain Monthly \
--time-period "{\"start-date\":\"$START\",\"end-date\":\"2027-12-31\"}" \
--notifications "{\"actual-80\":{\"enabled\":true,\"operator\":\"GreaterThanOrEqualTo\",\"threshold\":80.0,\"contact-emails\":[\"[email protected]\"]}}"
amount: 50, timeGrain: Monthly, and your notification with threshold: 80. If this group's spend ever crosses 40 in a month (80% of the 50, in your subscription's currency), that email fires. You have turned "watch the bill" into an automatic tripwire.Ask Advisor what you're wasting
Azure Advisor continuously analyses usage and produces cost recommendations — idle resources, oversized VMs, unbought reservations. Read the cost category from the CLI.
az advisor recommendation list --category Cost \
--query "[].{impact:impact, problem:shortDescription.problem}" -o table
Make storage tier and expire itself
The quiet cost killer is data nobody deletes. A lifecycle policy fixes it structurally: cool blobs after a month, delete them after a year — automatically, forever. Create a storage account and apply one.
SA="campuxcost$RANDOM"
az storage account create -n "$SA" -g "$RG" -l eastus --sku Standard_LRS
cat > policy.json <<'EOF'
{ "rules": [ {
"name": "tier-and-expire",
"enabled": true,
"type": "Lifecycle",
"definition": {
"filters": { "blobTypes": ["blockBlob"] },
"actions": { "baseBlob": {
"tierToCool": { "daysAfterModificationGreaterThan": 30 },
"delete": { "daysAfterModificationGreaterThan": 365 }
} }
}
} ] }
EOF
az storage account management-policy create \
--account-name "$SA" -g "$RG" --policy @policy.json
az storage account management-policy show --account-name "$SA" -g "$RG" \ --query "policy.rules[0].definition.actions.baseBlob" -o jsonYou see
tierToCool at 30 days and delete at 365. From now on this account moves ageing data to the cheaper Cool tier and removes year-old data on its own — cost control that runs without anyone remembering to.Tear it down
Delete the budget explicitly (it is a management object, not a resource in the group), then delete the group.
az consumption budget delete-with-rg --budget-name campux-monthly -g "$RG"
az group delete -n campux-lab-cost-rg --yes
az group exists -n campux-lab-cost-rg # -> false
What you can now honestly claim
You set a Cost Management budget with a threshold alert, queried Azure Advisor's cost recommendations, and applied a storage lifecycle policy that tiers and expires data automatically. That is "drive cost optimization initiatives, including right-sizing and lifecycle policies" — from the job description — implemented as controls rather than described as good intentions. Cost is where cloud engineers earn trust with the people who sign the invoices: a budget that warned the team at 80%, or a lifecycle policy that quietly saved thousands, is the kind of concrete outcome that reads well on a résumé and even better in a review.
- Budgets alert; they do not cap. Azure does not hard-stop spending when a budget is exceeded, because abruptly killing production to hit a number is usually worse than the overspend. To act automatically on a breach you wire the budget's alert to an action group that runs an automation — but the human-in-the-loop email is the sensible default and what most teams run.
- Advisor's cost recommendations can be empty on a new or lightly-used subscription — there is simply nothing oversized yet. That is not a failure of the command; it is the honest state of a tidy subscription. The value appears as real workloads accumulate and drift from their right size.