搭DescribeServices配 AWS SDK 或命令列工具使用 - AWS Support

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

DescribeServices配 AWS SDK 或命令列工具使用

下列程式碼範例會示範如何使用DescribeServices

動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:

.NET
AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫

/// <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 詳細資訊,請參閱 AWS SDK for .NET API 參考DescribeServices中的。

CLI
AWS CLI

列出 AWS 服務和服務類別

下列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" } ] } ] }

如需詳細資訊,請參閱 Sup AWS port 使用者指南中的案例管理

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DescribeServices中的。

Java
適用於 Java 2.x 的 SDK
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫

// 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 詳細資訊,請參閱 AWS SDK for Java 2.x API 參考DescribeServices中的。

Kotlin
適用於 Kotlin 的 SDK
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫

// 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 的詳細信息,請參閱 AWS SDK DescribeServices中的 Kotlin 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 詳細資訊,請參閱AWS Tools for PowerShell 指令程DescribeServices式參考中的。

Python
適用於 Python (Boto3) 的 SDK
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫

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 的詳細資訊,請參閱AWS 開發套件DescribeServices中的 Python (博托 3) API 參考。

如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱搭配 AWS SDK 使用 AWS Support。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。