Capstone: a small end-to-end pipeline inside a cost guard
Lesson opener
In one line: Copy, transform, train, register, and score locally, and refuse any step when the cost guard is off.
Why it matters: A Chennai pilot that "only forgot to delete compute" is how Azure labs get banned internally.
Before this lesson: Azure Machine Learning.
Before you start
| Resource | Link |
|---|---|
| Previous | Azure Machine Learning |
| Next | — |
| Prerequisites | az7 |
| Time | ~55 minutes |
What you will learn
By the end of this lesson you will be able to:
- Guard every step with a single
cost_guard_okflag. - Copy and transform a tiny orders table.
- Train and register a model version from those rows.
- Score one new city row through the stand-in endpoint.
- Print a teardown list: trigger, compute, endpoint, group.
- Keep the whole path off live Azure so the only bill is zero.
The path (still one resource group)
Real Azure would be: storage (raw) → Data Factory copy+transform → Azure SQL or lake (silver) → Azure ML train/register/endpoint. This capstone runs that sequence in process. If you later recreate it in the portal, use one resource group, the smallest SKUs, no trigger until debug is green, and delete the group the same day.
Cost. Do not create a VM, a compute cluster, or an online endpoint for this exercise. If you ignore that and create them anyway, delete the resource group before you log off. The cost guard below is the habit; the group delete is the brake.
Portal click-path if you recreate it later
- Create
rg-azure-capstone-YYYYMMDDin your lab subscription. - Storage (hierarchical namespace if you want folders) → container
raw→ upload ten rows. - Optional: Azure SQL or stay on the lake for silver.
- Data Factory: copy raw → silver, then stop. No trigger.
- Azure ML: train on the laptop (this script), register the file, do not deploy an online endpoint unless finance approved it.
- Delete the resource group. Confirm Cost analysis the next morning.
Demo 1 — Cost guard
def guarded(step: str, cost_guard_ok: bool) -> str:
if not cost_guard_ok:
return f"refuse:{step}"
return f"run:{step}"
print(guarded("copy", False))
print(guarded("copy", True))
assert guarded("train", False) == "refuse:train"Expected output:
refuse:copy
run:copyDemo 2 — Copy, transform, train, register, score
from sklearn.linear_model import LogisticRegression
def run_pipeline(cost_guard_ok: bool) -> dict:
if not cost_guard_ok:
return {"status": "refused"}
raw = [
{"city": " bengaluru", "tickets": 3, "churned": 1},
{"city": "pune", "tickets": 0, "churned": 0},
{"city": "mumbai", "tickets": 4, "churned": 1},
{"city": "pune", "tickets": 1, "churned": 0},
{"city": "jaipur", "tickets": 5, "churned": 1},
{"city": "noida", "tickets": 0, "churned": 0},
]
silver = []
for row in raw:
silver.append(
{
"city": row["city"].strip().title(),
"tickets": int(row["tickets"]),
"churned": int(row["churned"]),
}
)
X = [[r["tickets"]] for r in silver]
y = [r["churned"] for r in silver]
model = LogisticRegression(max_iter=200, random_state=42)
model.fit(X, y)
registry = {"churn-logit:1": {"version": 1, "n": len(silver)}}
label = int(model.predict([[4]])[0])
return {
"status": "ok",
"rows": len(silver),
"cities": sorted({r["city"] for r in silver}),
"registered": "churn-logit:1",
"score": label,
"model_version": registry["churn-logit:1"]["version"],
}
out = run_pipeline(True)
print(out["status"])
print(out["rows"])
print(out["registered"])
print(out["score"] in (0, 1))
assert out["rows"] == 6
assert "Bengaluru" in out["cities"]Expected output:
ok
6
churn-logit:1
TrueDemo 3 — Teardown list
def teardown() -> list[str]:
return [
"stop-or-delete-triggers",
"stop-compute-and-endpoints",
"delete-resource-group",
"check-cost-analysis-next-day",
]
steps = teardown()
print(len(steps))
print(steps[0])
print(steps[2])
assert steps[-1].startswith("check-cost")Expected output:
4
stop-or-delete-triggers
delete-resource-groupGuided practice: guard off
def run_pipeline(cost_guard_ok: bool) -> dict:
if not cost_guard_ok:
return {"status": "refused"}
return {"status": "ok"}
print(run_pipeline(False)["status"])
assert run_pipeline(False)["status"] == "refused"Expected output:
refusedIndependent practice: city count
Deliverable: run the silver step and print how many distinct cities landed.
raw = [
{"city": " bengaluru", "tickets": 3},
{"city": "pune", "tickets": 0},
{"city": "bengaluru", "tickets": 1},
]
cities = {row["city"].strip().title() for row in raw}
print(len(cities))
assert len(cities) == 2Expected output:
2Common mistake
The deliberate mistake
Symptom: the script is green on a laptop, then someone "just deploys the endpoint" for a demo and leaves it.
Diagnosis: the capstone succeeded locally; the bill is from an extra Azure resource.
Correction: delete the endpoint and the group. Re-run only the local script for the next demo.
Prevention: the cost guard is a flag on the ticket, not a comment in a notebook.
Snapshot — checked September 2026
- Recreating this path on live Azure uses the same product names as az4–az7 (Storage, Data Factory, Azure SQL optional, Azure Machine Learning). SKUs and free amounts move — re-read the create-blade estimate the day you click.
- A workspace often provisions a storage account automatically. Group delete is what removes those hidden helpers.
- Do not use production subscriptions for this capstone.
Where this connects
What you can now do:
- Run copy → transform → train → register → score behind a guard.
- Recite the teardown list in order.
- Keep the exercise off live compute.