有没有API可以列出所有Azure区域?

46

我想通过某些API列出所有Azure的区域(我需要为每个区域生成一些配置文件,并使用与Azure完全相同的命名方式,以避免拼写错误)。我找到了这个问题,但它仅列出特定订阅有权使用的区域。

我想列出存在的所有区域,无论我的订阅是否有访问权限。

6个回答

130

az account list-locations -o table

会给你一个如下的表格:

DisplayName               Name                 RegionalDisplayName
------------------------  -------------------  -------------------------------------
East US                   eastus               (US) East US
East US 2                 eastus2              (US) East US 2
South Central US          southcentralus       (US) South Central US
West US 2                 westus2              (US) West US 2
Australia East            australiaeast        (Asia Pacific) Australia East
Southeast Asia            southeastasia        (Asia Pacific) Southeast Asia
North Europe              northeurope          (Europe) North Europe
UK South                  uksouth              (Europe) UK South
West Europe               westeurope           (Europe) West Europe
Central US                centralus            (US) Central US
North Central US          northcentralus       (US) North Central US
West US                   westus               (US) West US
South Africa North        southafricanorth     (Africa) South Africa North
Central India             centralindia         (Asia Pacific) Central India
East Asia                 eastasia             (Asia Pacific) East Asia
Japan East                japaneast            (Asia Pacific) Japan East
JIO India West            jioindiawest         (Asia Pacific) JIO India West
Korea Central             koreacentral         (Asia Pacific) Korea Central
Canada Central            canadacentral        (Canada) Canada Central
France Central            francecentral        (Europe) France Central
Germany West Central      germanywestcentral   (Europe) Germany West Central
Norway East               norwayeast           (Europe) Norway East
Switzerland North         switzerlandnorth     (Europe) Switzerland North
UAE North                 uaenorth             (Middle East) UAE North
Brazil South              brazilsouth          (South America) Brazil South
Central US (Stage)        centralusstage       (US) Central US (Stage)
East US (Stage)           eastusstage          (US) East US (Stage)
East US 2 (Stage)         eastus2stage         (US) East US 2 (Stage)
North Central US (Stage)  northcentralusstage  (US) North Central US (Stage)
South Central US (Stage)  southcentralusstage  (US) South Central US (Stage)
West US (Stage)           westusstage          (US) West US (Stage)
West US 2 (Stage)         westus2stage         (US) West US 2 (Stage)
Asia                      asia                 Asia
Asia Pacific              asiapacific          Asia Pacific
Australia                 australia            Australia
Brazil                    brazil               Brazil
Canada                    canada               Canada
Europe                    europe               Europe
Global                    global               Global
India                     india                India
Japan                     japan                Japan
United Kingdom            uk                   United Kingdom
United States             unitedstates         United States
East Asia (Stage)         eastasiastage        (Asia Pacific) East Asia (Stage)
Southeast Asia (Stage)    southeastasiastage   (Asia Pacific) Southeast Asia (Stage)
Central US EUAP           centraluseuap        (US) Central US EUAP
East US 2 EUAP            eastus2euap          (US) East US 2 EUAP
West Central US           westcentralus        (US) West Central US
West US 3                 westus3              (US) West US 3
South Africa West         southafricawest      (Africa) South Africa West
Australia Central         australiacentral     (Asia Pacific) Australia Central
Australia Central 2       australiacentral2    (Asia Pacific) Australia Central 2
Australia Southeast       australiasoutheast   (Asia Pacific) Australia Southeast
Japan West                japanwest            (Asia Pacific) Japan West
Korea South               koreasouth           (Asia Pacific) Korea South
South India               southindia           (Asia Pacific) South India
West India                westindia            (Asia Pacific) West India
Canada East               canadaeast           (Canada) Canada East
France South              francesouth          (Europe) France South
Germany North             germanynorth         (Europe) Germany North
Norway West               norwaywest           (Europe) Norway West
Switzerland West          switzerlandwest      (Europe) Switzerland West
UK West                   ukwest               (Europe) UK West
UAE Central               uaecentral           (Middle East) UAE Central
Brazil Southeast          brazilsoutheast      (South America) Brazil Southeast

7
最佳平台不可知答案。 - FilBot3
3
这是我喜欢找到并在可能的情况下给自己的答案类型:从一个工程师到另一个着迷的工程师。谢谢。 - solr
它现在似乎输出有些改变。我得到了 DisplayName / Name / RegionalDisplayName - bytedev
1
@bytedev,只需省略[-o table]部分,您就可以获得完整的信息,以甜美的JSON格式呈现。 - Dmitry Shevkoplyas
列出当前订阅支持的区域。在我的情况下,此命令不会列出政府区域。详见https://learn.microsoft.com/en-us/cli/azure/account?view=azure-cli-latest#az-account-list-locations。 - jasiustasiu

18

Get-AzureRMLocation将为您提供针对您的帐户/租户/订阅运行的位置列表。

根据下面的答案,这在较新版本的Azure PS中可以完美运行!

Get-AzLocation | select DisplayName, Location | Format-Table

我想列出所有可用的位置,即使我的订阅没有访问权限(这样我就知道要请求哪些位置的访问权限)。那还能行吗? - aoetalks
我认为它使用与/providers cmdlets相同的代码 - 我不认为 Azure API 仅针对位置,所以 cmdlets 只是像其他解决方案一样包装调用...但适用于 Azure 中的所有资源类型,而不仅仅是 VM。 - bmoore-msft
使用Azure API时,有时位置以“显示名称”格式出现,有时以“位置”格式出现。例如,在调用SQL服务器信息时,位置将为“westus2”,但在请求应用程序服务列表时,它将为“West US 2”。看起来,小写字母和去除空格的版本只是这样做的,即小写字母和去除空格。这是微软计划继续保持的趋势,还是有其他方法可以使用另一种命名约定?我真希望微软在这方面更加一致。 - Rob S.
Rob - 你是在哪里看到的?(即,在你的情况下,你是如何获取位置信息的?)- 在“场景”内我们应该保持一致,但在Azure中有两种引用/使用位置的方式,因此不同的场景可能会暴露出不同的值... - bmoore-msft

4

这是一个旧问题,已经有了一个被接受的答案。但由于 Azure 模块有一些变化,因此在此添加最新的命令。

我认为位置的 API 已不再存在。但是,使用最新版本的 Powershell Az 模块,您可以获取位置。

Get-AzLocation | select DisplayName, Location | Format-Table

这为您提供了一些自由度,可以选择所需的属性并以表格格式格式化输出。 AZ CLI命令仍然与上面相同。

2
使用 PowerShell 脚本的一种可能解决方案是解析来自 URL:https://azure.microsoft.com/zh-cn/global-infrastructure/regions/ 的响应。使用此方法,您可以获取有关新宣布的区域的信息。
如果您不介意使用 Java 或 C#,那么以下解决方案也很方便。
  1. 在 Java 中获取区域列表的 Maven 依赖项为 azure-mgmt-resources,位于https://github.com/Azure/azure-libraries-for-java/tree/master/azure-mgmt-resources。 文档:https://azure.github.io/azure-sdk-for-java/com/microsoft/azure/management/resources/fluentcore/arm/Region.html

  2. 如果您正在使用 C#,则 NuGet 中的依赖项为Microsoft.Azure.Management.ResourceManager.Fluent。参考的源代码 URL:https://github.com/Azure/azure-libraries-for-net/blob/master/src/ResourceManagement/ResourceManager/Region.cs


不幸的是,这个可能有用的URL返回了404错误。 https://learn.microsoft.com/en-us/cli/azure/sql/db?view=azure-cli-latest - StvnBrkdll
1
但是我们如何获取显示名称呢?这只是内部名称。 - Morten_564834

1

我一直在寻找一种无需对Azure进行身份验证即可获取Azure地区的方法,并偶然发现了这个线程。与 @girip11 的回答类似,我一直在利用公共Azure文档进行开发。以下是获取数据的Python脚本:

import requests
import pandas as pd
from re import search


def list_azure_regions():
    url = 'https://azure.microsoft.com/en-us/explore/global-infrastructure/geographies/'
    html = requests.get(url).content
    df_list = pd.read_html(html)

    regions_list = []
    locations_list = []

    for df in df_list:
        for dc in list(df):
            if search('Regions', dc):
                pass
            else:
                if search('Coming soon', dc):
                    state = 'planned'
                else:
                    state = 'active'

                location = df[dc][0]
                region = dc.removesuffix('  Start free')
                region = region.removesuffix('  Get started')
                region = region.removesuffix('  Coming soon')
                if region in regions_list:
                    pass
                else:
                    regions_list.append(region)
                    locations_list.append(
                        dict({
                            'display_name': region,
                            'name': region.replace(' ','').lower(),
                            'location': location,
                            'state': state
                        })
                    )

    return locations_list

azure_regions = list_azure_regions()
print(azure_regions)

脚本返回一个类型为<class 'list'>的响应,但如果需要,可以转换成更易读的内容。例如,在Windows上运行时:
> python .\get-azure-regions.py | ConvertFrom-Json

display_name         name               location        state
------------         ----               --------        -----
East Asia            eastasia           Hong Kong       active
Southeast Asia       southeastasia      Singapore       active
Australia Central    australiacentral   Canberra        active
Australia East       australiaeast      New South Wales active
Australia Southeast  australiasoutheast Victoria        active
China East           chinaeast          Shanghai        active
China East 2         chinaeast2         Shanghai        active
China North          chinanorth         Beijing         active
China North 2        chinanorth2        Beijing         active
China North 3        chinanorth3        Hebei           active
Central India        centralindia       Pune            active
India South Central  indiasouthcentral  Hyderabad       active
South India          southindia         Chennai         active
Indonesia Central    indonesiacentral   Jakarta         planned
Japan East           japaneast          Tokyo, Saitama  active
Japan West           japanwest          Osaka           active
Korea Central        koreacentral       Seoul           active
Malaysia West        malaysiawest       Kuala Lumpur    planned
New Zealand North    newzealandnorth    Auckland        planned
Taiwan North         taiwannorth        Taipei          planned
Austria East         austriaeast        Vienna          planned
Belgium Central      belgiumcentral     Brussels        active
...

-1

1
这是关于提供程序而不是区域的。 - RichArt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接