CAMPUX Cloud Bootcamp Lab · Cost · FinOps ← All labs
Hands-On Lab · Beginner
~30 min · Free · Cloud Shell
CLI · torn down at the end
Cost · FinOps

Guardrails before the bill.

"Drive cost optimization" is in every senior cloud job, and it is not a spreadsheet — it is controls you put in the platform. Set a budget that emails you before spend runs away, read what Advisor says you are wasting, and make storage tier and expire itself. Three guardrails, all free to set.

Fig. 1 · A budget that warns, storage that expires
Resource group · rg-lab-costscopes + watches spendBudgetalert at 80%Storage accountcool tier · auto-expirecost is an engineering control, not a report
● Screen walkthrough Not yet recorded · ~7 min
Reel · 00:00 / 07:00

Set a budget, read what Advisor recommends, and add a lifecycle rule that trims storage spend automatically.

Placeholder — the page below stands alone until the reel lands
Why

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.

Before you begin — one-time setup

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.

The companion repository

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.

Setup

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
Checkpoint A resource group exists. Scoping a budget to a group (rather than the whole subscription) is how real teams give each project its own spend ceiling and alert list.
Step 1

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]\"]}}"
Checkpoint The command returns the budget as JSON — 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.
Step 2

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
Checkpoint You get a table of cost recommendations — or an empty list if this subscription is new and lightly used, which is itself a valid result (nothing to right-size yet). On a real subscription this list is the backbone of a right-sizing effort: each row is money, ranked by impact. The skill is reading it regularly and acting, not running it once.
Step 3

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
Checkpoint Read the policy back and see the rule in force:
az storage account management-policy show --account-name "$SA" -g "$RG" \
  --query "policy.rules[0].definition.actions.baseBlob" -o json
You 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.
Down

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
Checkpoint The budget is removed and the group is gone. Nothing here was billing anyway — guardrails are free; the spend they prevent is the point.
End

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.

Footnotes
  1. 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.
  2. 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.