0
0
Azurecloud~5 mins

Cost management and budgets in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Managing cloud costs helps you avoid surprises in your bills. Budgets let you set limits and get alerts when spending approaches those limits.
When you want to track how much your team spends on cloud resources each month
When you need to get notified before your cloud costs exceed a certain amount
When you want to compare actual spending against planned budgets
When you want to control costs by setting spending limits for projects
When you want to analyze spending trends to optimize resource use
Commands
This command sets the active subscription to 'Example Subscription' so that all following commands apply to it.
Terminal
az account set --subscription "Example Subscription"
Expected OutputExpected
No output (command runs silently)
--subscription - Specifies which subscription to use for commands
Creates a monthly budget named 'MyBudget' with a limit of 100 currency units for June 2024 in the specified subscription.
Terminal
az consumption budget create --name "MyBudget" --amount 100 --time-grain Monthly --start-date 2024-06-01 --end-date 2024-06-30 --subscription "Example Subscription"
Expected OutputExpected
{ "amount": 100.0, "category": "Cost", "currentSpend": { "amount": 0.0, "unit": "USD" }, "name": "MyBudget", "timeGrain": "Monthly", "timePeriod": { "startDate": "2024-06-01T00:00:00Z", "endDate": "2024-06-30T23:59:59Z" } }
--name - Names the budget
--amount - Sets the spending limit
--time-grain - Defines the budget period (Monthly)
--start-date - Sets the budget start date
--end-date - Sets the budget end date
Shows details of the budget named 'MyBudget' to check current spending and limits.
Terminal
az consumption budget show --name "MyBudget" --subscription "Example Subscription"
Expected OutputExpected
{ "amount": 100.0, "category": "Cost", "currentSpend": { "amount": 0.0, "unit": "USD" }, "name": "MyBudget", "timeGrain": "Monthly", "timePeriod": { "startDate": "2024-06-01T00:00:00Z", "endDate": "2024-06-30T23:59:59Z" } }
--name - Specifies the budget to show
Lists all budgets in the subscription to see all active budgets and their statuses.
Terminal
az consumption budget list --subscription "Example Subscription"
Expected OutputExpected
[ { "amount": 100.0, "category": "Cost", "currentSpend": { "amount": 0.0, "unit": "USD" }, "name": "MyBudget", "timeGrain": "Monthly", "timePeriod": { "startDate": "2024-06-01T00:00:00Z", "endDate": "2024-06-30T23:59:59Z" } } ]
Key Concept

If you remember nothing else from this pattern, remember: setting budgets helps you control cloud spending by alerting you before costs get too high.

Common Mistakes
Not setting the correct subscription before creating or viewing budgets
Commands will run on the wrong subscription, causing confusion or no budget found errors
Always run 'az account set --subscription "Your Subscription"' before budget commands
Using incorrect date formats or forgetting to set start and end dates
Budget creation fails or budgets do not cover the intended time period
Use ISO date format YYYY-MM-DD and specify both start and end dates when creating budgets
Summary
Set the active subscription to ensure commands apply to the right account.
Create a budget with a spending limit and time period to track costs.
Check budget details to monitor current spending against limits.
List all budgets to see an overview of cost controls in place.