Utilizzare DescribeServices con un SDK AWS o una CLI - Esempi di codice per SDK AWS

Sono disponibili altri esempi per SDK AWS nel repository GitHub della documentazione degli esempi per SDK AWS.

Utilizzare DescribeServices con un SDK AWS o una CLI

Gli esempi di codice seguenti mostrano come utilizzare DescribeServices.

Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. Puoi vedere questa azione nel contesto nel seguente esempio di codice:

.NET
SDK per .NET
Nota

Ulteriori informazioni su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel Repository di esempi di codice 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; }
  • Per informazioni dettagliate sull’API, consulta DescribeServices nella documentazione di riferimento dell’API AWS SDK per .NET.

CLI
AWS CLI

Come elencare i servizi AWS e le relative categorie

L’esempio describe-services seguente elenca le categorie dei servizi disponibili per la richiesta di informazioni generali.

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

Output:

{ "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" } ] } ] }

Per ulteriori informazioni, consulta Gestione dei casi nella Guida per l’utente del Supporto AWS.

  • Per informazioni dettagliate sull’API, consulta DescribeServices nella documentazione di riferimento dei comandi della AWS CLI.

Java
SDK per Java 2.x
Nota

Ulteriori informazioni su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel Repository di esempi di codice 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; }
  • Per informazioni dettagliate sull’API, consulta DescribeServices nella documentazione di riferimento dell’API AWS SDK for Java 2.x.

Kotlin
SDK per Kotlin
Nota

Ulteriori informazioni su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel Repository di esempi di codice 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.fromEnvironment { 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 }
  • Per informazioni dettagliate sull’API, consulta DescribeServices nella documentazione di riferimento dell’API AWS SDK per Kotlin.

PowerShell
Strumenti per PowerShell V4

Esempio 1: restituisce tutti i codici, i nomi e le categorie disponibili per il servizio.

Get-ASAService

Esempio 2: restituisce il nome e le categorie del servizio con il codice specificato.

Get-ASAService -ServiceCodeList "amazon-cloudfront"

Esempio 3: restituisce il nome e le categorie dei codici del servizio specificato.

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

Esempio 4: restituisce il nome e le categorie (in giapponese) dei codici del servizio specificato. Attualmente sono supportati i codici di lingua inglese (“en”) e giapponese (“ja”).

Get-ASAService -ServiceCodeList @("amazon-cloudfront", "amazon-cloudwatch") -Language "ja"
  • Per informazioni dettagliate sull’API, consulta DescribeServices nella documentazione di riferimento dei cmdlet di AWS Strumenti per PowerShell (V4).

Strumenti per PowerShell V5

Esempio 1: restituisce tutti i codici, i nomi e le categorie disponibili per il servizio.

Get-ASAService

Esempio 2: restituisce il nome e le categorie del servizio con il codice specificato.

Get-ASAService -ServiceCodeList "amazon-cloudfront"

Esempio 3: restituisce il nome e le categorie dei codici del servizio specificato.

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

Esempio 4: restituisce il nome e le categorie (in giapponese) dei codici del servizio specificato. Attualmente sono supportati i codici di lingua inglese (“en”) e giapponese (“ja”).

Get-ASAService -ServiceCodeList @("amazon-cloudfront", "amazon-cloudwatch") -Language "ja"
  • Per informazioni dettagliate sull’API, consulta DescribeServices nella documentazione di riferimento dei cmdlet di AWS Strumenti per PowerShell (V5).

Python
SDK per Python (Boto3)
Nota

Ulteriori informazioni su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel Repository di esempi di codice 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
  • Per informazioni dettagliate sull’API, consulta DescribeServices nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).