DescribeServices与 S Amazon DK 或命令行工具配合使用 - Amazon Web Services Support
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

DescribeServices与 S Amazon DK 或命令行工具配合使用

以下代码示例显示了如何使用DescribeServices

操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:

.NET
Amazon SDK for .NET
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/// <summary> /// Get the descriptions of AWS services. /// </summary> /// <param name="name">Optional language for services. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <returns>The list of AWS service descriptions.</returns> public async Task<List<Service>> DescribeServices(string language = "en") { var response = await _amazonSupport.DescribeServicesAsync( new DescribeServicesRequest() { Language = language }); return response.Services; }
  • 有关 API 的详细信息,请参阅 Amazon SDK for .NET API 参考DescribeServices中的。

CLI
Amazon CLI

列出 Amazon 服务和服务类别

以下 describe-services 示例列出了用于请求一般信息的可用服务类别。

aws support describe-services \ --service-code-list "general-info"

输出:

{ "services": [ { "code": "general-info", "name": "General Info and Getting Started", "categories": [ { "code": "charges", "name": "How Will I Be Charged?" }, { "code": "gdpr-queries", "name": "Data Privacy Query" }, { "code": "reserved-instances", "name": "Reserved Instances" }, { "code": "resource", "name": "Where is my Resource?" }, { "code": "using-aws", "name": "Using AWS & Services" }, { "code": "free-tier", "name": "Free Tier" }, { "code": "security-and-compliance", "name": "Security & Compliance" }, { "code": "account-structure", "name": "Account Structure" } ] } ] }

有关更多信息,请参阅《Amazon Support 用户指南》中的案例管理

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeServices中的。

Java
适用于 Java 2.x 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

// Return a List that contains a Service name and Category name. public static List<String> displayServices(SupportClient supportClient) { try { DescribeServicesRequest servicesRequest = DescribeServicesRequest.builder() .language("en") .build(); DescribeServicesResponse response = supportClient.describeServices(servicesRequest); String serviceCode = null; String catName = null; List<String> sevCatList = new ArrayList<>(); List<Service> services = response.services(); System.out.println("Get the first 10 services"); int index = 1; for (Service service : services) { if (index == 11) break; System.out.println("The Service name is: " + service.name()); if (service.name().compareTo("Account") == 0) serviceCode = service.code(); // Get the Categories for this service. List<Category> categories = service.categories(); for (Category cat : categories) { System.out.println("The category name is: " + cat.name()); if (cat.name().compareTo("Security") == 0) catName = cat.name(); } index++; } // Push the two values to the list. sevCatList.add(serviceCode); sevCatList.add(catName); return sevCatList; } catch (SupportException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } return null; }
  • 有关 API 的详细信息,请参阅 Amazon SDK for Java 2.x API 参考DescribeServices中的。

Kotlin
适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

// Return a List that contains a Service name and Category name. suspend fun displayServices(): List<String> { var serviceCode = "" var catName = "" val sevCatList = mutableListOf<String>() val servicesRequest = DescribeServicesRequest { language = "en" } SupportClient { region = "us-west-2" }.use { supportClient -> val response = supportClient.describeServices(servicesRequest) println("Get the first 10 services") var index = 1 response.services?.forEach { service -> if (index == 11) { return@forEach } println("The Service name is ${service.name}") if (service.name == "Account") { serviceCode = service.code.toString() } // Get the categories for this service. service.categories?.forEach { cat -> println("The category name is ${cat.name}") if (cat.name == "Security") { catName = cat.name!! } } index++ } } // Push the two values to the list. serviceCode.let { sevCatList.add(it) } catName.let { sevCatList.add(it) } return sevCatList }
  • 有关 API 的详细信息,请参阅适用DescribeServices于 K otlin 的Amazon SDK API 参考

PowerShell
用于 PowerShell

示例 1:返回所有可用的服务代码、名称和类别。

Get-ASAService

示例 2:返回带有指定代码的服务的名称和类别。

Get-ASAService -ServiceCodeList "amazon-cloudfront"

示例 3:返回指定服务代码的名称和类别。

Get-ASAService -ServiceCodeList @("amazon-cloudfront", "amazon-cloudwatch")

示例 4:返回指定服务代码的名称和类别(日语)。目前支持英语(“en”)和日语(“ja”)语言代码。

Get-ASAService -ServiceCodeList @("amazon-cloudfront", "amazon-cloudwatch") -Language "ja"
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考DescribeServices中的。

Python
SDK for Python (Boto3)
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

class SupportWrapper: """Encapsulates Support actions.""" def __init__(self, support_client): """ :param support_client: A Boto3 Support client. """ self.support_client = support_client @classmethod def from_client(cls): """ Instantiates this class from a Boto3 client. """ support_client = boto3.client("support") return cls(support_client) def describe_services(self, language): """ Get the descriptions of AWS services available for support for a language. :param language: The language for support services. Currently, only "en" (English) and "ja" (Japanese) are supported. :return: The list of AWS service descriptions. """ try: response = self.support_client.describe_services(language=language) services = response["services"] except ClientError as err: if err.response["Error"]["Code"] == "SubscriptionRequiredException": logger.info( "You must have a Business, Enterprise On-Ramp, or Enterprise Support " "plan to use the AWS Support API. \n\tPlease upgrade your subscription to run these " "examples." ) else: logger.error( "Couldn't get Support services for language %s. Here's why: %s: %s", language, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return services
  • 有关 API 的详细信息,请参阅适用DescribeServicesPython 的Amazon SDK (Boto3) API 参考

有关 S Amazon DK 开发者指南和代码示例的完整列表,请参阅将 Amazon Web Services Support 与 Amazon 开发工具包配合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。