简体   繁体   English

如何从 boto3 调用中获取一个区域中可用的 AWS 服务列表

[英]How to get list of available AWS services in a region from boto3 call

I want to use boto3 to get list of available aws services in a specific region.我想使用 boto3 获取特定区域的可用 aws 服务列表。 Is there any way to do this.有什么办法可以做到这一点。 I tried using Session object:我尝试使用 Session object:

session = boto3.Session(region_name='ap-south-1').get_available_services()

but it is giving me all the AWS services.但它为我提供了所有 AWS 服务。 For eg: Cloudsearch is not present in ap-south-1, but this function still gives me the service in the output. Also, I don't want to use ssm service get_parameters_by_path function as I don't want to give ssm permission.例如:Cloudsearch 不存在于 ap-south-1 中,但是这个 function 仍然为我提供 output 中的服务。此外,我不想使用 ssm service get_parameters_by_path function,因为我不想授予 ssm 权限。 Any other way?还有别的办法吗?

To be frank, I reckon, your best bet actually is the Systems Manager Parameter Store .坦率地说,我认为您最好的选择实际上Systems Manager Parameter Store

For example, you can easily display a complete list of all available AWS services, sort them into alphabetical order, and, for the brevity, show the first 10.例如,您可以轻松显示所有可用 AWS 服务的完整列表,将它们按字母顺序排序,并为简洁起见,显示前 10 个。

$ aws ssm get-parameters-by-path \
  --path /aws/service/global-infrastructure/services --output json | \
  jq '.Parameters[].Name' | sort | head -10

Output: Output:

"/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"

And here's how to get the list of services that are available in a given region.以下是获取给定区域可用服务列表的方法。 Show first 10 and sorted.显示前 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

But... if you want any other way you might want to try AWS Price List API .但是...如果您想要任何其他方式,您可能想尝试AWS 价目表 API

With the AWS Price List Query API, you can query specific information about AWS services, products, and pricing using an AWS SDK or the AWS CLI.通过 AWS 价目表查询 API,您可以使用 AWS SDK 或 AWS CLI 查询有关 AWS 服务、产品和定价的特定信息。

This obviously can be narrowed down to a specific region.这显然可以缩小到特定区域。 If there's a price, there is a service.有价格就有服务。

I got this by below code:我通过以下代码得到了这个:

resp = boto3.Session().get_available_regions('cloudsearch')

This gave me the list of all the regions where cloudsearch service is available.这给了我可以使用云搜索服务的所有区域的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM