是否有 Amazon API 来获取 Nice Region 名称而不是 us-west1?

Is there an Amazon API to get Nice Region names rather than us-west1?

我正在使用以下 API 检索亚马逊区域列表。

但是,它基本上 returns 区域为“us-west1、us-west2”等。有没有办法从 API 中获取区域名称并输出如“US”西部(加利福尼亚北部)”、“美国西部(俄勒冈)”?

    // Get a list of regions from our default region
    svc := ec2.NewFromConfig(cfg)
    result, err := svc.DescribeRegions(context.TODO(), &ec2.DescribeRegionsInput{})
    if err != nil {
        return nil, err
    }

    var regions []portaineree.Pair
    for _, region := range result.Regions {
        fmt.Println("region.Name=", *region.RegionName)
       // do something with region...
    }

如果可以的话,这可以通过 CLI 命令很容易地完成

region=us-east-1
aws ssm get-parameter --name /aws/service/global-infrastructure/regions/$region/longName --query "Parameter.Value" --output text```

您可以使用 SSM 代理获取区域列表,并提取每个区域的长名称:

package main

import (
    "log"
    "strings"

    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/ssm"
)

func main() {
    // Build a AWS SSM Agent
    sess := session.Must(session.NewSessionWithOptions(session.Options{
        SharedConfigState: session.SharedConfigEnable,
    }))

    // We're requesting global data, the region doesn't matter
    svc := ssm.New(sess, &aws.Config{Region: aws.String("us-east-1")})
    var nextToken *string
    for {
        // Request all regions, paginating the results if needed
        var input = &ssm.GetParametersByPathInput{
            Path:      aws.String("/aws/service/global-infrastructure/regions"),
            NextToken: nextToken,
        }
        var output, err = svc.GetParametersByPath(input)
        if err != nil {
            log.Fatal(err)
        }

        // For each region, get the "longName" for the region
        for _, element := range output.Parameters {
            region := (*element.Name)[strings.LastIndex(*element.Name, "/")+1:]

            var regionInfo, err = svc.GetParameter(&ssm.GetParameterInput{
                Name: aws.String("/aws/service/global-infrastructure/regions/" + region + "/longName"),
            })
            if err != nil {
                log.Fatal(err)
            }

            regionDesc := *regionInfo.Parameter.Value

            // Just output the region and region description
            log.Println(region, " = ", regionDesc)
        }

        // Pull in the next page of regions if needed
        nextToken = output.NextToken
        if nextToken == nil {
            break
        }
    }
}