Bird
Raised Fist0
Azurecloud~5 mins

Cost optimization pillar in Azure - Commands & Configuration

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Managing cloud costs is important to avoid paying more than needed. The cost optimization pillar helps you use Azure resources efficiently and save money while keeping your apps running well.
When you want to reduce your monthly Azure bill without affecting app performance
When you need to find unused or underused resources to delete or resize
When you want to set budgets and alerts to avoid unexpected charges
When you want to choose the right Azure service plans that fit your workload
When you want to automate turning off resources during non-working hours
Commands
This command creates a monthly budget of $100 for the resource group 'example-group' to help track and control spending.
Terminal
az costmanagement budget create --name MyBudget --resource-group example-group --amount 100 --time-grain Monthly --start-date 2024-06-01 --end-date 2025-06-01
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-group/providers/Microsoft.Consumption/budgets/MyBudget", "name": "MyBudget", "properties": { "amount": 100.0, "timeGrain": "Monthly", "timePeriod": { "startDate": "2024-06-01T00:00:00Z", "endDate": "2025-06-01T00:00:00Z" }, "category": "Cost" }, "type": "Microsoft.Consumption/budgets" }
--amount - Sets the budget limit in dollars
--time-grain - Defines the budget period (Monthly here)
This command shows the total cost used so far this month to help monitor spending against the budget.
Terminal
az costmanagement query --type Usage --timeframe MonthToDate --dataset-aggregation totalCost=sum --dataset-granularity None
Expected OutputExpected
{ "properties": { "rows": [ [75.23] ] } }
--timeframe - Specifies the time range for cost data
This command lists all running virtual machines with their names and sizes to identify costly resources that might be resized or stopped.
Terminal
az vm list --query "[?powerState=='VM running'].{Name:name, Size:hardwareProfile.vmSize}" -o table
Expected OutputExpected
Name Size -------------- --------- my-vm-01 Standard_B2s my-vm-02 Standard_D2s_v3
--query - Filters and formats the output to show only running VMs with specific details
-o table - Displays output in a readable table format
This command stops and deallocates the VM 'my-vm-01' to save costs when the VM is not needed.
Terminal
az vm deallocate --resource-group example-group --name my-vm-01
Expected OutputExpected
No output (command runs silently)
--resource-group - Specifies the resource group of the VM
--name - Specifies the VM name to stop
Key Concept

If you remember nothing else from this pattern, remember: tracking and controlling your cloud spending regularly helps avoid surprises and saves money.

Common Mistakes
Not setting budgets or alerts in Azure Cost Management
Without budgets, you may not notice overspending until the bill arrives
Always create budgets with alerts to monitor and control costs proactively
Leaving unused or idle virtual machines running
Running VMs incur charges even if not used, wasting money
Regularly check VM usage and deallocate or delete VMs when not needed
Choosing VM sizes or services larger than needed
Oversized resources cost more without improving performance if workload is small
Select resource sizes based on actual workload requirements and scale as needed
Summary
Create budgets in Azure to set spending limits and receive alerts.
Use cost queries to monitor current spending against budgets.
List running resources like VMs to find cost-saving opportunities.
Stop or resize resources that are idle or oversized to reduce costs.

Practice

(1/5)
1. What is the main goal of the Cost optimization pillar in Azure cloud?
easy
A. To improve network speed only
B. To save money by using cloud resources wisely
C. To add more storage without limits
D. To increase the number of virtual machines

Solution

  1. Step 1: Understand the purpose of cost optimization

    The cost optimization pillar focuses on managing cloud spending efficiently.
  2. Step 2: Identify the correct goal

    Saving money by using resources wisely matches the cost optimization goal.
  3. Final Answer:

    To save money by using cloud resources wisely -> Option B
  4. Quick Check:

    Cost optimization = saving money [OK]
Hint: Cost optimization means saving money smartly [OK]
Common Mistakes:
  • Thinking cost optimization means adding more resources
  • Confusing cost optimization with performance only
  • Assuming cost optimization ignores resource usage
2. Which Azure tool helps you monitor and control your cloud spending?
easy
A. Azure Cost Management
B. Azure DevOps
C. Azure Active Directory
D. Azure Monitor Logs

Solution

  1. Step 1: Identify Azure tools related to cost

    Azure Cost Management is designed to track and manage cloud expenses.
  2. Step 2: Exclude unrelated tools

    DevOps is for development, Active Directory for identity, Monitor Logs for diagnostics.
  3. Final Answer:

    Azure Cost Management -> Option A
  4. Quick Check:

    Cost Management = spending control [OK]
Hint: Cost Management tracks spending in Azure [OK]
Common Mistakes:
  • Choosing Azure DevOps for cost tracking
  • Confusing Azure Monitor Logs with cost tools
  • Selecting Azure Active Directory by mistake
3. You have an Azure VM running 24/7 but only need it during business hours (8 AM to 6 PM). What is the best cost optimization action?
medium
A. Keep the VM running all the time
B. Resize the VM to a larger size
C. Schedule the VM to start and stop during business hours
D. Add more storage to the VM

Solution

  1. Step 1: Analyze VM usage pattern

    The VM is needed only during business hours, so running it 24/7 wastes money.
  2. Step 2: Choose cost-saving action

    Scheduling start/stop saves cost by not running VM when unused.
  3. Final Answer:

    Schedule the VM to start and stop during business hours -> Option C
  4. Quick Check:

    Stop unused VM times = save cost [OK]
Hint: Stop VMs when not needed to save money [OK]
Common Mistakes:
  • Keeping VM always on wastes money
  • Resizing larger increases cost
  • Adding storage does not reduce cost
4. You see a recommendation from Azure Advisor to "Right-size your VMs" but your VM is already the smallest size. What should you do?
medium
A. Check if VM is underutilized and consider shutting down
B. Ignore the recommendation because VM is smallest
C. Upgrade VM to a larger size
D. Delete the VM immediately

Solution

  1. Step 1: Understand "Right-size" recommendation

    It means adjusting VM size to match workload, avoiding waste.
  2. Step 2: Since VM is smallest, check if it is needed at all

    If underutilized, shutting down or deleting saves cost.
  3. Final Answer:

    Check if VM is underutilized and consider shutting down -> Option A
  4. Quick Check:

    Right-size means match usage, not just smallest [OK]
Hint: Right-size means match workload, not just smallest size [OK]
Common Mistakes:
  • Ignoring recommendations blindly
  • Upgrading VM increases cost unnecessarily
  • Deleting VM without checking usage
5. Your company wants to reduce Azure costs by using reserved instances. Which approach best fits cost optimization?
hard
A. Ignore reserved instances and focus on storage only
B. Use pay-as-you-go for all workloads to stay flexible
C. Always use the largest VM size available
D. Purchase reserved instances for steady workloads to get discounts

Solution

  1. Step 1: Understand reserved instances

    Reserved instances offer discounts for long-term, steady usage.
  2. Step 2: Match reserved instances to steady workloads

    This reduces cost compared to pay-as-you-go for predictable use.
  3. Final Answer:

    Purchase reserved instances for steady workloads to get discounts -> Option D
  4. Quick Check:

    Reserved instances = save on steady use [OK]
Hint: Reserved instances save money for steady workloads [OK]
Common Mistakes:
  • Using pay-as-you-go for steady workloads wastes money
  • Choosing largest VM size increases cost
  • Ignoring reserved instances misses savings