Run code on a consumption plan, and compare how compute is bought

short · 30 min · Skills measured 1.1

Task

Create a function app on the Azure Functions Consumption plan, add one HTTP-triggered function, run it, and confirm that Azure, not you, chose and runs the servers underneath: there is no virtual machine size anywhere. Then use the Azure pricing calculator to see how the same virtual machine is priced under pay-as-you-go, a savings plan for compute and a reservation, and how an Azure Functions estimate is built from executions and execution time rather than hours of a server. You finish able to explain the consumption-based model, the trade-off between the pricing models, and why serverless still has servers. Everything you create is deleted at the end with one command.

Steps

  1. Open Cloud Shell (Bash) and create the lab's resource group, so the clean-up is one delete:
az group create --name az900-lab02-rg --location eastus

Choose your five digits for NNNNN now and write them down. 2. Create the storage account Azure Functions needs for the app's files and state. It is private, and nothing in it can be read anonymously:

az storage account create --name az900lab02NNNNN --resource-group az900-lab02-rg --location eastus --sku Standard_LRS --kind StorageV2 --allow-blob-public-access false --min-tls-version TLS1_2

If Azure says the name is taken, choose other digits and use them from here on. 3. Create the function app on the Consumption plan, then look at the plan Azure made for it:

az functionapp create --name az900fn02NNNNN --resource-group az900-lab02-rg --storage-account az900lab02NNNNN --consumption-plan-location eastus --os-type Windows --runtime powershell --runtime-version 7.4 --functions-version 4 --disable-app-insights true
az functionapp plan list --resource-group az900-lab02-rg --query '[].{name:name, sku:sku.name, tier:sku.tier}' -o table

The table shows one plan with the SKU Y1 and the tier Dynamic: that is the Consumption plan. Notice what you were never asked: how many servers, what size, which operating system patches. --consumption-plan-location is what makes this serverless; --disable-app-insights true stops the CLI from also creating a monitoring resource this lab does not need. 4. Add a function and run it. In the portal, open the function app az900fn02NNNNN. On Overview, under Functions, choose Create function (the button may read Create in Azure portal). Select the HTTP trigger template, name the function HttpTrigger1, keep Authorization level as Function, which needs a key to call it, and choose Create. Open the function, choose Code + Test, then Test/Run, keep the method GET and choose Run. The output shows the HTTP response code 200 and a short greeting. That run was an event, an HTTP request. On the Consumption plan you are billed mainly for the number of executions and the time the code runs, not for a server waiting between requests, and the platform scales out and back in by itself. 5. Compare the pricing models for the same virtual machine. In a new browser tab, open the Azure pricing calculator (search for "Azure pricing calculator"; you do not need to sign in). Add Virtual Machines, set the region to East US and keep the default Linux size. In the virtual machine's savings options, switch between pay as you go, a one-year and a three-year savings plan, and a one-year and a three-year reservation, and watch the monthly estimate change. Write down only which option is lowest and which is highest, not the figures, because prices change. Nothing here is bought: the calculator only estimates. 6. See how serverless is priced. In the same calculator, add Azure Functions and look at the Consumption tier's inputs: memory size, execution time and executions per month. There is no server size and no hours field. Set executions to a small number and then to a large one, and watch the estimate follow usage. That is the consumption-based model: costs rise with use and fall when use stops, and there was nothing to buy before starting. 7. Choose the pricing model for each workload: pay-as-you-go, a reservation, a savings plan for compute, or Spot. (a) A database server that must run around the clock, unchanged, for three years. (b) A company whose overall compute spend is steady, but which keeps changing VM sizes and moving workloads between regions. (c) A batch job that can stop and restart at any time without harm. (d) A trial project that may be cancelled in a few weeks. (e) A team that shuts its reserved VMs down every night and expects to save money: what is wrong? Check your answers in the Notes.

Verify

Confirm the function app runs on the Consumption plan and holds your function:

az functionapp show --name az900fn02NNNNN --resource-group az900-lab02-rg --query state -o tsv

Expected output: Running.

az functionapp plan list --resource-group az900-lab02-rg --query '[0].sku.tier' -o tsv

Expected output: Dynamic.

az functionapp function show --name az900fn02NNNNN --resource-group az900-lab02-rg --function-name HttpTrigger1 --query isDisabled -o tsv

Expected output: false: the function exists and is enabled.

Cost and clean-up

Charges are possible but small while the lab runs: the storage account is billed for what it stores and the operations on it, and the Consumption plan for executions and execution time. An idle Consumption function app costs little or nothing. The pricing calculator costs nothing and buys nothing. Delete the resource group the same day.

Created by this lab: the resource group az900-lab02-rg; the storage account az900lab02NNNNN, with the file share Azure Functions makes in it for the app's content; the function app az900fn02NNNNN and the function HttpTrigger1 in it; the Consumption plan Azure creates for the function app.

  1. Delete the resource group. This deletes the function app az900fn02NNNNN, its function HttpTrigger1, the Consumption plan and the storage account az900lab02NNNNN with everything in it, in one go:
az group delete --name az900-lab02-rg --yes

It can take a few minutes. Close the pricing calculator tab without saving anything.

Check it is gone

az group exists --name az900-lab02-rg

Expected output: false.

Notes

Step 7 answers. (a) A reservation: steady and unchanging, one resource type in one region. (b) A savings plan for compute: a fixed hourly spend whose discount follows the workload across sizes and regions. (c) Spot: the cheapest compute, but Azure can evict it at short notice, so only for interruptible work. (d) Pay-as-you-go: no commitment, and charges stop when the resource is deleted. (e) A reservation is charged for the whole term whether or not the matching VMs run, so stopping them at night saves nothing and wastes the discount.

Serverless still has servers: the function you ran executed on one. Microsoft provisions, patches and scales them, and you never see them. Azure Functions is code first; Azure Logic Apps, the other serverless service in lesson 2, builds workflows in a visual designer with prebuilt connectors.

If the CLI reports that --runtime-version 7.4 is not supported, run az functionapp list-runtimes --os windows -o table and use the newest PowerShell version it lists.

This is an independent study companion for the Microsoft Azure Fundamentals (AZ-900) exam and is not produced by or endorsed by Microsoft. Microsoft, Azure and Microsoft Entra are trademarks of the Microsoft group of companies.

This is an independent study companion for Microsoft Azure Fundamentals AZ-900 and is not produced by or endorsed by CompTIA.