Utilizzare CreateCase 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 CreateCase con un SDK AWS o una CLI

Gli esempi di codice seguenti mostrano come utilizzare CreateCase.

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> /// Create a new support case. /// </summary> /// <param name="serviceCode">Service code for the new case.</param> /// <param name="categoryCode">Category for the new case.</param> /// <param name="severityCode">Severity code for the new case.</param> /// <param name="subject">Subject of the new case.</param> /// <param name="body">Body text of the new case.</param> /// <param name="language">Optional language support for your case. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <param name="attachmentSetId">Optional Id for an attachment set for the new case.</param> /// <param name="issueType">Optional issue type for the new case. Options are "customer-service" or "technical".</param> /// <returns>The caseId of the new support case.</returns> public async Task<string> CreateCase(string serviceCode, string categoryCode, string severityCode, string subject, string body, string language = "en", string? attachmentSetId = null, string issueType = "customer-service") { var response = await _amazonSupport.CreateCaseAsync( new CreateCaseRequest() { ServiceCode = serviceCode, CategoryCode = categoryCode, SeverityCode = severityCode, Subject = subject, Language = language, AttachmentSetId = attachmentSetId, IssueType = issueType, CommunicationBody = body }); return response.CaseId; }
  • Per informazioni dettagliate sull’API, consulta CreateCase nella documentazione di riferimento dell’API AWS SDK per .NET.

CLI
AWS CLI

Come creare un caso

L’esempio create-case seguente crea un caso di supporto per l’account AWS in uso.

aws support create-case \ --category-code "using-aws" \ --cc-email-addresses "myemail@example.com" \ --communication-body "I want to learn more about an AWS service." \ --issue-type "technical" \ --language "en" \ --service-code "general-info" \ --severity-code "low" \ --subject "Question about my account"

Output:

{ "caseId": "case-12345678910-2013-c4c1d2bf33c5cf47" }

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

  • Per informazioni dettagliate sull’API, consulta CreateCase 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.

public static String createSupportCase(SupportClient supportClient, List<String> sevCatList, String sevLevel) { try { String serviceCode = sevCatList.get(0); String caseCat = sevCatList.get(1); CreateCaseRequest caseRequest = CreateCaseRequest.builder() .categoryCode(caseCat.toLowerCase()) .serviceCode(serviceCode.toLowerCase()) .severityCode(sevLevel.toLowerCase()) .communicationBody("Test issue with " + serviceCode.toLowerCase()) .subject("Test case, please ignore") .language("en") .issueType("technical") .build(); CreateCaseResponse response = supportClient.createCase(caseRequest); return response.caseId(); } catch (SupportException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } return ""; }
  • Per informazioni dettagliate sull’API, consulta CreateCase nella documentazione di riferimento dell’API AWS SDK for Java 2.x.

JavaScript
SDK per JavaScript (v3)
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.

import { CreateCaseCommand } from "@aws-sdk/client-support"; import { client } from "../libs/client.js"; export const main = async () => { try { // Create a new case and log the case id. // Important: This creates a real support case in your account. const response = await client.send( new CreateCaseCommand({ // The subject line of the case. subject: "IGNORE: Test case", // Use DescribeServices to find available service codes for each service. serviceCode: "service-quicksight-end-user", // Use DescribeSecurityLevels to find available severity codes for your support plan. severityCode: "low", // Use DescribeServices to find available category codes for each service. categoryCode: "end-user-support", // The main description of the support case. communicationBody: "This is a test. Please ignore.", }), ); console.log(response.caseId); return response; } catch (err) { console.error(err); } };
  • Per informazioni dettagliate sull’API, consulta CreateCase nella documentazione di riferimento dell’API AWS SDK per JavaScript.

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.

suspend fun createSupportCase( sevCatListVal: List<String>, sevLevelVal: String, ): String? { val serCode = sevCatListVal[0] val caseCategory = sevCatListVal[1] val caseRequest = CreateCaseRequest { categoryCode = caseCategory.lowercase(Locale.getDefault()) serviceCode = serCode.lowercase(Locale.getDefault()) severityCode = sevLevelVal.lowercase(Locale.getDefault()) communicationBody = "Test issue with ${serCode.lowercase(Locale.getDefault())}" subject = "Test case, please ignore" language = "en" issueType = "technical" } SupportClient.fromEnvironment { region = "us-west-2" }.use { supportClient -> val response = supportClient.createCase(caseRequest) return response.caseId } }
  • Per informazioni dettagliate sull’API, consulta CreateCase nella documentazione di riferimento dell’SDK AWS per API Kotlin.

PowerShell
Strumenti per PowerShell V4

Esempio 1: crea un nuovo caso nel Centro di Supporto AWS. I valori per i parametri -ServiceCode e -CategoryCode possono essere ottenuti utilizzando il cmdlet Get-ASAService. Il valore per il parametro -SeverityCode può essere ottenuto utilizzando il cmdlet Get-ASASeverityLevel. Il valore del parametro -IssueType può essere “customer-service” or “technical”. Se l’operazione ha esito positivo, viene restituito il numero del caso del Supporto AWS. Per impostazione predefinita, il caso verrà gestito in inglese. Per utilizzare il giapponese, aggiungi il parametro -Language “ja”. I parametri -ServiceCode, -CategoryCode, -Subject e -CommunicationBody sono obbligatori.

New-ASACase -ServiceCode "amazon-cloudfront" -CategoryCode "APIs" -SeverityCode "low" -Subject "subject text" -CommunicationBody "description of the case" -CcEmailAddress @("email1@domain.com", "email2@domain.com") -IssueType "technical"
  • Per informazioni dettagliate sull’API, consulta CreateCase nella documentazione di riferimento dei cmdlet di AWS Strumenti per PowerShell (V4).

Strumenti per PowerShell V5

Esempio 1: crea un nuovo caso nel Centro di Supporto AWS. I valori per i parametri -ServiceCode e -CategoryCode possono essere ottenuti utilizzando il cmdlet Get-ASAService. Il valore per il parametro -SeverityCode può essere ottenuto utilizzando il cmdlet Get-ASASeverityLevel. Il valore del parametro -IssueType può essere “customer-service” or “technical”. Se l’operazione ha esito positivo, viene restituito il numero del caso del Supporto AWS. Per impostazione predefinita, il caso verrà gestito in inglese. Per utilizzare il giapponese, aggiungi il parametro -Language “ja”. I parametri -ServiceCode, -CategoryCode, -Subject e -CommunicationBody sono obbligatori.

New-ASACase -ServiceCode "amazon-cloudfront" -CategoryCode "APIs" -SeverityCode "low" -Subject "subject text" -CommunicationBody "description of the case" -CcEmailAddress @("email1@domain.com", "email2@domain.com") -IssueType "technical"
  • Per informazioni dettagliate sull’API, consulta CreateCase 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 create_case(self, service, category, severity): """ Create a new support case. :param service: The service to use for the new case. :param category: The category to use for the new case. :param severity: The severity to use for the new case. :return: The caseId of the new case. """ try: response = self.support_client.create_case( subject="Example case for testing, ignore.", serviceCode=service["code"], severityCode=severity["code"], categoryCode=category["code"], communicationBody="Example support case body.", language="en", issueType="customer-service", ) case_id = response["caseId"] 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 create case. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return case_id
  • Per informazioni dettagliate sull’API, consulta CreateCase nella documentazione di riferimento dell’API SDK AWS per Python (Boto3).