AWS Support
用户指南 (API 版本 2013-04-15)
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 Amazon AWS 入门

AWS Support 案例生命周期编程

您可以使用 AWS Support API 创建案例,并在您调查问题及与 AWS Support 人员交流的整个过程中在案例中添加通信信息。此主题演示了如何使用 AWS Support 服务中的操作,并介绍了 AWS Support 中心的很多行为以作为范例。

有关详细信息,请参阅 AWS Support API Reference

概述

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

注意

如果您在调用 AWS Support 时遇到服务限制,请按 AWS 中的错误重试和指数回退中的建议操作

结合使用 IAM 与 AWS Support API

AWS Support API 支持 AWS Identity and Access Management (IAM)。有关更多信息,请参阅访问 AWS Support

创建 AWS Support 客户端

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

有关 AWS 证书的更多信息,请参阅 AWS General Reference 中的 AWS 安全证书

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

发现 AWS 服务和问题严重性级别

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

以下 Java 代码段演示了对 AWS Support DescribeServicesDescribeSeverityLevel 操作的调用:

// 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 还返回适用于每一种 AWS 服务的 AWS Support 类别的列表。这些类别还用于通过 createCase 开立支持案例。虽然这些值也可以从 AWS Support 站点本身获得,但 AWS 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; }

创建支持案例

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

  • ServiceCode。您根据上一节所述通过调用 DescribeServices 获得的 AWS Support 服务代码。

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

  • Language。AWS Support 提供支持时所用语言的代码。当前,AWS 支持英语 (en) 和日语 (ja)。

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

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

  • Subject。支持案例的标题。

  • SeverityCode。调用 DescribeSeverityLevels 返回的值之一。

  • AttachmentSetId。(可选)要包括到案例中的文件附件集合的 ID。AddAttachmentsToSet 操作可返回该 ID。

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

  • case-123456789012-muen-2012-74a757cd8cf7558a

注意

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

public static void createCase(AWSSupportClient client) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter an AWS 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()); }

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

AWS Support 案例通常会涉及到客户与 AWS Support 专业人士的沟通。AWS Support 提供 DescribeCommunicationsDescribeAttachment 操作来检索此通信信息,​并提供 AddAttachmentsToSetAddCommunicationToCase 操作来更新案例。这些操作使用 Communication 数据类型将更新传递给服务,并将它们返回到您的代码。

以下 Java 代码段将通信信息添加到 AWS 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 an AWS 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 值列表,因此您可以在单次调用中检索多个案例的通信信息。

检索所有支持案例信息

您可以通过调用 DescribeCases 操作检索与您的 AWS Support 案例关联的所有信息。您用 ClientId 值列表填充 DescribeCasesRequest 数据类型,这些值在成功的 createCase 请求返回时由每个案例返回。

以下 Java 代码段接受从控制台接受 CaseId 值,并填充 DescribeCasesRequest 实例以供 DescribeCases 操作使用。为方便起见,提供了一个私有 printCases 方法。

public static void getCases(AWSSupportClient client) { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter an AWS 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 AWS 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 操作所用的参数可用来控制案例数量、案例类型和所检索的详细信息的数量。有关更多信息,请参阅DescribeCases

解决支持案例

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

public static void resolveSupportCase(AWSSupportClient client) { System.out.println( "Enter the AWS 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()); }