为 Amazon Web Services Support 案例编程 - Amazon Web Services Support
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

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

为 Amazon Web Services Support 案例编程

您可以使用Amazon Web Services SupportAPI 以编程方式创建支持案例,而不是使用Amazon Web Services Support将中心位于Amazon Web Services Management Console. 您可以添加通信并将文件附加到您的问题,以便支持代理可以调查并帮助解决您的问题。本主题提供有关如何使用Amazon Web Services SupportAPI 操作。

Notes
  • 有关 API 操作、参数和您可用于的数据类型的列表Amazon Web Services Support,请参阅Amazon Web Services SupportAPI 参考.

  • 有关支持Amazon Web Services SupportAPI 中,选择一个操作名称,例如CreateCase,并在另请参阅部分中,选择您的首选语言。

Overview

此主题使用 Java 代码示例演示 Amazon Web Services Support 的用法。有关开发工具包支持的更多信息,请参阅示例代码和库

注意

如果您的调用超出了服务配额Amazon Web Services Support,请参阅以下信息:

将 IAM 与Amazon Web Services SupportAPI

Amazon Identity and Access Management(IAM) 受Amazon Web Services SupportAPI。有关更多信息,请参阅 的访问权限Amazon Web Services Support

创建 Amazon Web Services Support 客户端

下方 Java 代码段显示了如何创建用于调用 AWSSupportServiceAWSSupportClientcreateClient 方法通过不带任何参数调用的 AWSSupportClient() 构造函数来获取 Amazon 凭证,该构造函数将从凭证提供程序链中检索凭证。有关此过程的更多信息,请参阅教程:使用 IAM 角色和Amazon SDK for Java中的Amazon SDK for Java.

有关 的更多信息Amazon凭据,请参阅Amazon安全凭证中的Amazon一般参考.

private static AWSSupportClient createClient() { AWSSupportClient client = new AWSSupportClient(); client.setEndpoint("https://support.cn-north-1.amazonaws.com.cn"); return client; }

发现 Amazon Web Services 和发布严重性级别

Amazon Web Services Support Java 客户端提供了 CreateCaseRequest 类型,用于以编程方式向 Amazon Web Services Support 提交案例。CreateCaseRequest 是一个结构,在填充请求参数后传递给 AWSSupportClient 实例上的 createClient 方法。这些参数包括指定 Amazon 服务和案例严重性的代码。

以下 Java 代码段演示了对Amazon Web Services Support DescribeServicesDDescribeSeverityLevel操作。

// DescribeServices example public static void getServiceCodes(AWSSupportClient client) { DescribeServicesResult result = client.describeServices(); for (Service service : result.getServices()) { System.out.println("Service code (name): " + service.getCode() + "(" + service.getName() + ")"); for (Category category : service.getCategories()) { System.out.println(" Category code (name): " + category.getCode() + "(" + category.getName() + ")"); } } } // DescribeSeverityLevels example public static void getSeverityLevels(AWSSupportClient client) { DescribeSeverityLevelsResult result = client.describeSeverityLevels(); for (SeverityLevel level : result.getSeverityLevelsList()) { System.out.println("Severity level (name): " + level.getCode() + level.getName() + ")"); } }

每个调用均返回 JSON 格式的对象的列表。DescribeServices 返回服务代码及其相应的名称,DescribeSeverityLevels 返回严重性级别及其相应的名称。此外,DescribeServices 还返回适用于每一种 Amazon 服务的 Amazon Web Services Support 类别的列表。这些类别还用于通过开立支持案例时,使用CreateCaseoperation. 虽然这些值也可以从Amazon Web Services Support站点,Amazon Web Services Support服务始终会返回此信息的最新版本。

创建附件集合

要为案例附加文件,必须在创建案例之前将附件添加到附件集合中。您最多可在一个附件集中添加 3 个附件,且附件集中任何附件的最大大小为 5 MB。有关更多信息,请参阅 AddAttachmentsToSet

以下 Java 代码段创建一个文本文件附件,将它添加到一个附件集合,然后获取该附件集合的 ID 以便添加到案例中。

public static string createAttachmentSet() throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); // Get content and file name for an attachment. System.out.println("Enter text content for an attachment to the case: "); String attachmentcontent = null; try { attachmentcontent = reader.readLine().trim(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.out.println("Enter the file name for the attachment: "); String attachmentfilename = null; try { attachmentfilename = reader.readLine().trim(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } // Create the attachment. Attachment attachment1 = new Attachment(); attachment1.setData(ByteBuffer.wrap(attachmentcontent.getBytes())); attachment1.setFileName("attachmentfilename"); // Add the attachment to an array list. List<Attachment> attachments = new ArrayList<Attachment>(); attachments.add(attachment1); // Create an attachment set and add the attachment array list to it. AddAttachmentsToSetRequest addAttachmentsToSetRequest = new AddAttachmentsToSetRequest(); addAttachmentsToSetRequest.setAttachments(attachments); AddAttachmentsToSetResult addAttachmentsToSetResult = client.addAttachmentsToSet(addAttachmentsToSetRequest); // Get the ID of the attachment set. String attachmentsetid = addAttachmentsToSetResult.getAttachmentSetId(); System.out.println("Attachment ID: " + attachmentsetid); return attachmentsetid; }

创建支持案例

要使用 Amazon Web Services Support 服务创建 Amazon Web Services Support 案例,请使用以下信息填充 CreateCaseRequest 实例:

  • ServiceCode—Amazon Web Services Support通过调用DescribeServices操作,如上一节中所述。

  • CategoryCode— 描述支持案例所涉及的问题的类型的类别代码。

  • Language— 用于语言的代码Amazon Web Services Support在中提供了支持。当前,Amazon 支持英语 (en) 和日语 (ja)。

  • CcEmailAddresses— 用于接收后续通信信息副本的电子邮件地址的列表。

  • CommunicationBody— 最初所提交的案例的正文文本。

  • Subject— 支持案例的标题。

  • SeverityCode— 调用返回的值之一DescribeSeverityLevels.

  • AttachmentSetId—(可选)要纳入到案例中的一系列文件附件的 ID。AddAttachmentsToSet 操作可返回该 ID。

以下 Java 代码段从命令行收集每个案例创建参数的值。然后,它通过在 AWSSupportClient 实例上调用 createCase 方法填充 CreateCaseRequest 实例并将其传递给 Amazon Web Services Support。如果调用成功,该代码会返回以下格式的 Amazon Web Services Support CaseId 值:

case-123456789012-muen-2012-74a757cd8cf7558a
注意

Amazon Web Services Support 提供 CaseIdDisplayId 字段。DisplayId 字段对应于 Amazon Web Services Support 站点上显示的案例编号。CaseId 字段用于以编程方式与 Amazon Web Services Support 服务交互。这两个字段都通过 CaseDetails 数据类型公开。

public static void createCase(AWSSupportClient client) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter an Amazon service code: "); String servicecode = null; try { servicecode = reader.readLine().trim(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.out.println("Enter a category code: "); String categorycode = null; try { categorycode = reader.readLine().trim(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.out.println("Enter a language code, 'en' for English: "); String language = null; try { language = reader.readLine().trim(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.out.println("Enter an email address to copy on correspondence: "); String ccemailaddress = null; try { ccemailaddress = reader.readLine().trim(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.out.println("Enter body text for the case: "); String communicationbody = null; try { communicationbody = reader.readLine().trim(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.out.println("Enter a subject for the case: "); String casesubject = null; try { casesubject = reader.readLine().trim(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.out.println("Enter the severity code for the case: "); String severitycode = null; try { severitycode = reader.readLine().trim(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.out.println("Enter the attachment set ID for the case: "); String attachmentsetid = null; try { attachmentsetid = reader.readLine().trim(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } CreateCaseRequest request = new CreateCaseRequest() .withServiceCode(servicecode) .withCategoryCode(categorycode) .withLanguage(language) .withCcEmailAddresses(ccemailaddress) .withCommunicationBody(communicationbody) .withSubject(casesubject) .withSeverityCode(severitycode) .withAttachmentSetId(attachmentsetid); CreateCaseResult result = client.createCase(request); System.out.println("CreateCase() Example: Case created with ID " + result.getCaseId()); }

检索和更新支持案例通信信息

Amazon Web Services Support情况下通常会导致客户之间的沟通和Amazon Web Services Support专业人士。Amazon Web Services Support提供DescribeCommunicationsDescribeAttachment操作来检索此对应关系,AddAttachmentsToSetAddCommunicationToCase操作来更新案例。这些操作使用Communication数据类型将更新传递给服务,并将它们返回到您的代码。

以下 Java 代码段将通信信息添加到 Amazon Web Services Support 案例。在示例中,为方便起见,提供了一个私有 printCommunications 方法。

public static void addCommunication(AWSSupportClient client) { System.out.println("Enter the CaseID for the case you want to update."); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String caseid = null; try { caseid = reader.readLine().trim(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.out.println("Enter text you want to add to this case."); String addcomm = null; try { addcomm = reader.readLine().trim(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } AddCommunicationToCaseRequest request = new AddCommunicationToCaseRequest().withCaseId(caseid) .withCommunicationBody(addcomm); client.addCommunicationToCase(request); System.out.println( "AddCommunication() Example: Call GetCommunications() " + "if you want to see if the communication was added."); } // DescribeCommunications example public static void getCommunications(AWSSupportClient client) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String caseNumber = null; System.out.println("Enter a CaseID"); caseNumber = reader.readLine().trim(); { DescribeCommunicationsRequest request = new DescribeCommunicationsRequest() .withCaseId(caseNumber.toString()); DescribeCommunicationsResult result = client.describeCommunications(request); printCommunications(result.getCommunications()); // Get more pages. while (result.getNextToken() != null) { request.setNextToken(result.getNextToken()); result = client.describeCommunications(request); printCommunications(result.getCommunications()); System.out.println( "GetCommunications() Example: Case communications retrieved" + " for case number " + request.getCaseId().toString()); } } } private static void printCommunications(List<Communication> communications) { for (Communication communication : communications) { System.out.println("SubmittedBy: " + communication.getSubmittedBy()); System.out.println(" Body: " + communication.getBody()); } }
注意

DescribeCommunications 返回一个支持案例的五条最近的通信信息。此外,DescribeCommunications 还接受 CaseId 值列表,以便您可以在单次调用中检索多个案例的通信信息。

检索所有支持案例信息

您可以检索与您的Amazon Web Services Support案例,方法是调用DescribeCasesoperation. 您用 ClientId 值列表填充 DescribeCasesRequest 数据类型,这些值在成功的 createCase 请求返回时由每个案例返回。

以下 Java 代码段接受CaseId值,并填充DescribeCasesRequest实例以供DescribeCasesoperation. 为方便起见,提供了一个私有 printCases 方法。

public static void getCases(AWSSupportClient client) { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter an Amazon Web Services Support Case ID"); String caseid = null; try { caseid = reader.readLine().trim(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } DescribeCasesRequest request = new DescribeCasesRequest(); request.withCaseIdList(caseid); DescribeCasesResult result = client.describeCases(request); printCases(result.getCases()); // Get more pages. while (result.getNextToken() != null) { request.setNextToken(result.getNextToken()); result = client.describeCases(request); printCases(result.getCases()); } } private static void printCases(List<CaseDetails> caseDetailsList) { for (CaseDetails caseDetails : caseDetailsList) { System.out.println( "Case ID: " + caseDetails.getCaseId()); // This ID is for API use. System.out.println( " Display ID: " + caseDetails.getDisplayId()); // This ID is displayed on the Amazon Web Services Support website. System.out.println(" Language: " + caseDetails.getLanguage()); System.out.println(" Status: " + caseDetails.getStatus()); System.out.println(" Subject: " + caseDetails.getSubject()); System.out.println("Recent Communications: " + caseDetails.getRecentCommunications()); } }
注意

这些区域有:DescribeCases操作所用的参数可用来控制要检索的案例数量、案例类型和详细信息数量。有关更多信息,请参阅 。DescribeCasesoperation.

解决支持案例

Amazon Web Services Support提供ResolveCase操作来解决您自己的支持案例。以下 Java 代码示例演示了该操作的用法。

public static void resolveSupportCase(AWSSupportClient client) { System.out.println( "Enter the Amazon Web Services Support case ID for the case you want to resolve."); BufferedReader BR = new BufferedReader(new InputStreamReader(System.in)); String caseid = null; try { caseid = BR.readLine().trim(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } ResolveCaseResult rcr = client.resolveCase(new ResolveCaseRequest().withCaseId(caseid)); System.out.println("Initial case status: " + rcr.getInitialCaseStatus()); System.out.println("Final case status: " + rcr.getFinalCaseStatus()); }

适用于的服务配额Amazon Web Services SupportAPI

下表描述了Amazon Web Services SupportAPI。

资源

默认值

最大数Amazon Web Services Support您可以创建的案例。

每小时 10 个

在中国(北京)区域,您最多可以创建 240 个Amazon Web Services Support每天的案例。

最大数Amazon Web Services SupportAPI每秒可以执行的操作。

5

最大数Amazon Trusted AdvisorAPI每秒可以执行的操作。

100