亚马逊AWS官方博客

新增功能 – 使用 AWS Systems Manager Parameter Store 查询 AWS 区域、终端节点等

为响应 AWS 客户的请求,我一直要求我们的服务团队寻找方法,以编程方式提供关于我们的区域和服务的信息。今天,我很高兴地宣布这些信息已在 AWS Systems Manager Parameter Store 中提供,而且您可以通过自己的脚本和代码轻松访问这些信息。您可以获得活动区域的完整列表,了解这些区域提供哪些服务等。

运行查询
在下面的大部分示例中,我将使用 AWS 命令行接口 (CLI);您也可以使用适用于 Windows PowerShell 的 AWS 工具或任何 AWS 开发工具包。与所有 CLI 命令一样,您可以请求以 JSON、制表符分隔文本或表格格式输出。我将使用 JSON,并灵活使用 jq 实用程序,显示每次查询时最相关的输出部分。

以下示例为如何查询活动区域列表:

$ aws ssm get-parameters-by-path \
  --path /aws/service/global-infrastructure/regions --output json | \
  jq .Parameters[].Name
"/aws/service/global-infrastructure/regions/ap-northeast-1"
"/aws/service/global-infrastructure/regions/eu-central-1"
"/aws/service/global-infrastructure/regions/eu-north-1"
"/aws/service/global-infrastructure/regions/eu-west-1"
"/aws/service/global-infrastructure/regions/eu-west-3"
"/aws/service/global-infrastructure/regions/sa-east-1"
"/aws/service/global-infrastructure/regions/us-east-2"
"/aws/service/global-infrastructure/regions/us-gov-east-1"
"/aws/service/global-infrastructure/regions/us-gov-west-1"
"/aws/service/global-infrastructure/regions/us-west-1"
"/aws/service/global-infrastructure/regions/ap-northeast-2"
"/aws/service/global-infrastructure/regions/ap-northeast-3"
"/aws/service/global-infrastructure/regions/ap-south-1"
"/aws/service/global-infrastructure/regions/ap-southeast-1"
"/aws/service/global-infrastructure/regions/ap-southeast-2"
"/aws/service/global-infrastructure/regions/ca-central-1"
"/aws/service/global-infrastructure/regions/cn-north-1"
"/aws/service/global-infrastructure/regions/cn-northwest-1"
"/aws/service/global-infrastructure/regions/eu-west-2"
"/aws/service/global-infrastructure/regions/us-west-2"
"/aws/service/global-infrastructure/regions/us-east-1"

以下示例为如何显示所有可用 AWS 服务的完整列表,将它们按字母顺序排列,并显示前 10 项服务(在我写这篇文章时,共有 155 项服务):

$ aws ssm get-parameters-by-path \
  --path /aws/service/global-infrastructure/services --output json | \
  jq .Parameters[].Name | sort | head -10
"/aws/service/global-infrastructure/services/acm"
"/aws/service/global-infrastructure/services/acm-pca"
"/aws/service/global-infrastructure/services/alexaforbusiness"
"/aws/service/global-infrastructure/services/apigateway"
"/aws/service/global-infrastructure/services/application-autoscaling"
"/aws/service/global-infrastructure/services/appmesh"
"/aws/service/global-infrastructure/services/appstream"
"/aws/service/global-infrastructure/services/appsync"
"/aws/service/global-infrastructure/services/athena"
"/aws/service/global-infrastructure/services/autoscaling"

以下示例为如何获取指定区域中可用服务的列表(同上,排序列出前 10 项服务):

$ aws ssm get-parameters-by-path \
  --path /aws/service/global-infrastructure/regions/us-east-1/services --output json | \
  jq .Parameters[].Name | sort | head -10
"/aws/service/global-infrastructure/regions/us-east-1/services/acm"
"/aws/service/global-infrastructure/regions/us-east-1/services/acm-pca"
"/aws/service/global-infrastructure/regions/us-east-1/services/alexaforbusiness"
"/aws/service/global-infrastructure/regions/us-east-1/services/apigateway"
"/aws/service/global-infrastructure/regions/us-east-1/services/application-autoscaling"
"/aws/service/global-infrastructure/regions/us-east-1/services/appmesh"
"/aws/service/global-infrastructure/regions/us-east-1/services/appstream"
"/aws/service/global-infrastructure/regions/us-east-1/services/appsync"
"/aws/service/global-infrastructure/regions/us-east-1/services/athena"
"/aws/service/global-infrastructure/regions/us-east-1/services/autoscaling"

以下示例为如何获取服务(在此示例中为 Amazon Athena)可用区域的列表:

$ aws ssm get-parameters-by-path \
  --path /aws/service/global-infrastructure/services/athena/regions --output json | \
  jq .Parameters[].Value
"ap-northeast-2"
"ap-south-1"
"ap-southeast-2"
"ca-central-1"
"eu-central-1"
"eu-west-1"
"eu-west-2"
"us-east-1"
"us-east-2"
"us-gov-west-1"
"ap-northeast-1"
"ap-southeast-1"
"us-west-2"

以下示例为如何使用路径获取服务名称:

$ aws ssm get-parameters-by-path \
  --path /aws/service/global-infrastructure/services/athena --output json | \
  jq .Parameters[].Value
"Amazon Athena"

以下示例为如何找到指定服务的区域终端节点,同样也是使用路径查找:

$ aws ssm get-parameter \
  --name /aws/service/global-infrastructure/regions/us-west-1/services/s3/endpoint \
  --output json | \
  jq .Parameter.Value
"s3.us-west-1.amazonaws.com"

现已推出
这些数据现已推出,您可以立即开始免费使用。

Jeff

附注:特别感谢我的同事 Blake CopenhaverPhil Cali 为此文章提供的帮助!

 

本篇作者

Jeff Barr

AWS 首席布道师; 2004年开始发布博客,此后便笔耕不辍。