当用户从下拉菜单中选择亚马逊服务(s3、CloudFront等)时,我希望仅显示所选服务可用的区域/位置。
如何确定这些信息?是否可以使用RestAPI或dotNet查询Amazon的全球基础设施区域表?
如何确定这些信息?是否可以使用RestAPI或dotNet查询Amazon的全球基础设施区域表?
/aws/service/global-infrastructure/services/athena/regions
。在@adi-dembak的回答之后,以下是我在.net中完成此任务的步骤。
在AWS中添加以下SSM托管策略并将策略分配给用户。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "rule1",
"Effect": "Allow",
"Action": [
"ssm:PutParameter",
"ssm:GetParametersByPath"
],
"Resource": "*"
}
]}
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且不为空,则必须将其添加到请求中进行另一次调用。