Microsoft Azure Code Examples

Listing Regions and Zones

Using the Azure CLI (az)

List all available regions:

az account list-locations --output table

Using the Azure SDK for Python

Python script to list all available regions:


    from azure.identity import DefaultAzureCredential
    from azure.mgmt.resource import ResourceManagementClient

    credential = DefaultAzureCredential()
    subscription_id = 'your-subscription-id'
    client = ResourceManagementClient(credential, subscription_id)

    for location in client.locations.list():
        print(location.name)