是否有 API 来列出所有 Azure 区域?

Is there an API to list all Azure Regions?

我想通过一些 API 列出所有 Azure 位置(我需要为每个区域生成一些配置文件,并使用 Azure 所做的准确命名以避免拼写错误)。我找到了 ,但它只列出了特定订阅有权使用的区域。

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

Get-AzureRMLocation 会为您提供 account/tenant/subscription 的位置列表,您 运行 它反对。

根据下面的回答,这与较新版本的 Azure PS!

完美配合
Get-AzLocation | select DisplayName, Location | Format-Table

使用 powershell 脚本的可能解决方案是解析来自 URL 的响应:https://azure.microsoft.com/en-us/regions/。使用它,您可以获得有关新发布区域的信息。

如果您不介意使用 Java 或 C#,那么以下解决方案也很方便。

  1. 对于 java 中的区域列表,maven 中的依赖项是位于 https://github.com/Azure/azure-libraries-for-java/tree/master/azure-mgmt-resourcesazure-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

az account list-locations -o table

会给你一个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

这是一个老问题,已经有一个公认的答案。但考虑到 Azure 模块几乎没有变化,因此在此处添加最新的命令。

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

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

这让您可以自由地 select 您需要的 属性 并以表格格式格式化输出。 AZ CLI命令还是和上面一样。

您可以使用以下 REST API: https://management.azure.com/subscriptions/**YOUR_SUBSCRIPTION_ID**/providers?api -version=2020-10-01

参见:

但是,与 PowerShell 和 AZ 命令行一样,这仅显示指定订阅可用的数据中心区域。