访问亚马逊全球基础设施区域表(用于 RestAPI 或 dotNet)

6
当用户从下拉菜单中选择亚马逊服务(s3、CloudFront等)时,我希望仅显示所选服务可用的区域/位置。
如何确定这些信息?是否可以使用RestAPI或dotNet查询Amazon的全球基础设施区域表
2个回答

3
AWS系统管理器可以协助此事。它有多种语言的SDK以及一个rest API。
例如,要获取AWS Athena的所有区域,您可以使用GetParametersByPath和路径/aws/service/global-infrastructure/services/athena/regions

1

在@adi-dembak的回答之后,以下是我在.net中完成此任务的步骤。

在AWS中添加以下SSM托管策略并将策略分配给用户。

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "rule1",
        "Effect": "Allow",
        "Action": [
            "ssm:PutParameter",
            "ssm:GetParametersByPath"
        ],
        "Resource": "*"
    }
]}

安装 AWSSDK.SimpleSystemsManagement
        string accessKey = "123##";
        string secretKey = "321##";

        HashSet<string> hash = new HashSet<string>();

        AmazonSimpleSystemsManagementClient amazonSimpleSystemsManagementClient =
            new AmazonSimpleSystemsManagementClient(accessKey, secretKey, Amazon.RegionEndpoint.USEast1);

        GetParametersByPathRequest getParametersByPathRequest = new GetParametersByPathRequest();
        getParametersByPathRequest.Path = "/aws/service/global-infrastructure/services/s3/regions/";
        getParametersByPathRequest.Recursive = true;

        GetParametersByPathResponse getParametersByPathResponse;

        do
        {
            getParametersByPathResponse = await amazonSimpleSystemsManagementClient.GetParametersByPathAsync(getParametersByPathRequest);
            foreach (Parameter item in getParametersByPathResponse.Parameters)
            {
                hash.Add(item.Value);

            }
            getParametersByPathRequest.NextToken = getParametersByPathResponse.NextToken;
        }
        while ((getParametersByPathResponse.NextToken != null) && !string.IsNullOrEmpty(getParametersByPathResponse.NextToken.ToString()));

        //Print HashSet
        foreach (string item in hash)
        {
            Console.WriteLine(item);
        }

GetParametersByPath是一个分页操作。每次调用后,您必须从结果对象中检索NextToken,如果它不为null且不为空,则必须将其添加到请求中进行另一次调用。


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