
Cloud
Learning Level
from azure.costmanagement import CostManagementClient
def calculate_department_costs(subscription_id, department_tag):
client = CostManagementClient(credential)
query = {
"type": "Usage",
"timeframe": "MonthToDate",
"dataset": {
"granularity": "Daily",
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"grouping": [
{
"type": "Dimension",
"name": "ResourceGroup"
}
],
"filter": {
"dimensions": {
"name": "Tags",
"operator": "In",
"values": [department_tag]
}
}
}
}
return client.query.usage(subscription_id, query)# Create automation runbook for cost enforcement
az automation runbook create \
--name "StopHighCostResources" \
--resource-group myResourceGroup \
--automation-account-name myAutomationAccount \
--type PowerShell \
--location eastus# Analyze RI recommendations
az reservations list-catalog \
--query "[?contains(name, 'VM')] | [0:5]"
# Purchase optimal RIs
az reservations purchase \
--sku Standard_B2s \
--term P3Y \
--scope SingleImplement enterprise governance frameworks.
Resources
Ojasa Mirai
Master AI-powered development skills through structured learning, real projects, and verified credentials. Whether you're upskilling your team or launching your career, we deliver the skills companies actually need.
Learn Deep • Build Real • Verify Skills • Launch Forward