您好我想使用区域手段获取亚马逊网络服务(aws)地区名称
region is "us-east-1" region name is "US East (N. Virginia)"
region is "us-west-2" region name is "US West (Oregon)"
使用us-east-1区域我想动态显示区域名称“US East(N。Virginia)”。
由于 桑杰
答案 0 :(得分:5)
没有AWS API方法可以调用来获取此信息。
某些SDK(例如适用于.NET的AWS开发工具包)会将此信息附加到SDK中。例如,在C#中:
var regions = Amazon.RegionEndpoint.EnumerableAllRegions;
foreach (var r in regions)
{
Console.WriteLine("{0} -> {1}", r.SystemName, r.DisplayName);
}
查看AWS SDK for Java的文档,我找不到相应的内容。如果它在那里,我认为它应该在com.amazonaws.regions.Region
类。
您可能需要创建自己的映射。
答案 1 :(得分:1)
事实证明,这实际上是通过LightSail提供的 - 有意义的是包含主要针对新来者的服务经验不足的信息。
aws lightsail get-regions
{
"regions": [
{
"continentCode": "NA",
"description": "This region is recommended to serve users in the eastern United States and eastern Canada",
"displayName": "Virginia",
"name": "us-east-1",
"availabilityZones": []
},
....
OP可能不再寻找答案了,但万一有人在谷歌上搜索。
答案 2 :(得分:0)
检查此示例CLI命令" aws ec2 describe-regions --filters" Name = endpoint,Values = us ""。您需要使用JQ或--query选项单独提取Region名称。
此处有更多详情 - http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-regions.html
答案 3 :(得分:0)
Java AWS客户端具有一个Regions类,该类将提供此信息,例如:
for(Regions region : Regions.getEnumConstants()) {
System.out.println( String.sprintf("%-15s %s", region.getName(), (Regions.fromName(region.getName())).getDescription()))
}
输出:
us-gov-west-1 AWS GovCloud (US)
us-gov-east-1 AWS GovCloud (US-East)
us-east-1 US East (N. Virginia)
us-east-2 US East (Ohio)
us-west-1 US West (N. California)
us-west-2 US West (Oregon)
eu-west-1 EU (Ireland)
eu-west-2 EU (London)
eu-west-3 EU (Paris)
eu-central-1 EU (Frankfurt)
eu-north-1 EU (Stockholm)
ap-south-1 Asia Pacific (Mumbai)
ap-southeast-1 Asia Pacific (Singapore)
ap-southeast-2 Asia Pacific (Sydney)
ap-northeast-1 Asia Pacific (Tokyo)
ap-northeast-2 Asia Pacific (Seoul)
sa-east-1 South America (Sao Paulo)
cn-north-1 China (Beijing)
cn-northwest-1 China (Ningxia)
ca-central-1 Canada (Central)
对于我的AWS SDK客户端,我正在使用
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.537</version>
</dependency>
答案 4 :(得分:0)
对于独立于语言的实现,这里(希望)是所有区域的最新JSON(至少2020年初可用于我自己的帐户)。正如其他答案所同意的那样,没有编程的方法可以实现这一目标,因此唯一的解决方法是手动构建区域名称和相应友好名称的地图。
{
"ap-northeast-1": "Asia Pacific (Tokyo)",
"ap-northeast-2": "Asia Pacific (Seoul)",
"ap-southeast-1": "Asia Pacific (Singapore)",
"ap-southeast-2": "Asia Pacific (Sydney)",
"ap-south-1": "Asia Pacific (Mumbai)",
"eu-central-1": "EU (Frankfurt)",
"eu-north-1": "Europe (Stockholm)",
"eu-west-1": "EU (Ireland)",
"eu-west-2": "Europe (London)",
"eu-west-3": "Europe (Paris)",
"us-east-1": "US East (N. Virginia)",
"us-east-2": "US East (Ohio)",
"us-west-1": "US West (N. California)",
"us-west-2": "US West (Oregon)",
"sa-east-1": "South America (Sao Paulo)",
"ca-central-1": "Canada (Central)"
}
例如,ruby实现看起来像
require 'json'
require 'aws-sdk-ec2'
data = JSON.load File.read 'regions.json'
all_regions = Aws::EC2::Client.new.describe_regions.regions
all_regions.each { |r| puts "#{data[r.region_name]} - #{r.region_name}" }