Azure Classroomnotes 03/Mar/2022

Activity 1: Lets create an Azure Function which runs on schedule Every hour on weekday (Contd)..

  • Lets try to fetch all the resources in the current subscription when this function is executed.
  • From code to query about the details of Azure, We need to use Azure Libraries
  • Using Azure Libraries ensures we can automate the activities
    • Scenario: Ensure you run all the Virtual machines during 10:00 – 19:00 PM Every weekday for the dev environment. Once the time is not in range shutdown all the vm’s to save costs.
  • To connect to Azure Account/Subscription from code we need to use azure. For this there is a package called as azure-identity Refer Here
  • For admins: Create an Azure Function app with powershell core as runtime
  • For developers: Writing Code to list all the resources in python
from azure.identity import AzureCliCredential
from azure.mgmt.resource import ResourceManagementClient

if __name__ == "__main__":
    credential = AzureCliCredential()
    subscription_id = "-------------"

    # create a resource management client
    resource_manager_client = ResourceManagementClient(credential, subscription_id)

    rg_list = resource_manager_client.resource_groups.list()
    for rg in rg_list:

    resource_list = resource_manager_client.resources.list()
    for resource in resource_list:
        print(f"name = {}, type = {resource.type}")

  • Now we need to ensure this code runs in Azure function but we need to change the credential as AzureCliCredential will not work on Azure Functions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner