使用SDK查找未使用的资源



使用python SDK有没有找到订阅中未使用资源的好方法?

我使用ResourceManagementClient找到了有关更改时间的信息,但我认为这不是最好的来源。

您可以尝试以下代码:

import os
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
subscription_id = os.environ.get(
'AZURE_SUBSCRIPTION_ID',
'11111111-1111-1111-1111-111111111111') # your Azure Subscription Id
credentials = ServicePrincipalCredentials(
client_id=os.environ['AZURE_CLIENT_ID'],
secret=os.environ['AZURE_CLIENT_SECRET'],
tenant=os.environ['AZURE_TENANT_ID']
)
client = ResourceManagementClient(credentials, subscription_id)
for item in client.resource_groups.list():
print_item(item)

请参阅以下文件了解更多信息
使用Python管理Azure资源和资源组,
使用Azure库列出资源组和资源,
Finding Unused resources Impacting Azure Costs

最新更新