AWS Support ケースのプログラミング
AWS Management Console で AWS Support センターを使用する代わりに、AWS Support API を使用して、サポートケースをプログラムで作成できます。サポート担当者が問題の調査と解決を支援できるように、通信文を追加してケースにファイルを添付できます。このトピックでは、AWS Support API オペレーションの使用方法の例を示します。
-
AWS Support で使用できる API オペレーション、パラメータ、およびデータ型のリストについては、「AWS Support API リファレンス」を参照してください。
-
AWS Support API をサポートする言語のリストについては、オペレーション名 (CreateCase など) を選択し、「See Also」(参照) セクションで目的の言語を選択します。
トピック
Overview
このトピックでは、AWS Supportの使用方法を説明するために、Java コード例を使用しています。SDK サポートの詳細については、サンプルコードとライブラリ
AWS Support への呼び出しでサービスクォータを超過した場合、以下の情報を参照してください。
-
AWS 全般のリファレンスの「AWS でのエラー再試行とエクスポネンシャルバックオフ」を参照してください。
AWS Support API での IAM の使用
AWS Identity and Access Management (IAM) は AWS Support API でサポートされています。詳細については、「AWS Support へのアクセス許可」を参照してください。
AWS Support クライアントの作成
次の Java コードスニペットは、AWSSupportClient
を作成し、AWSSupportService
の呼び出しに使用する方法を示しています。createClient
メソッドは、AWS コンストラクタをパラメータなしで呼び出して AWSSupportClient()
認証情報を取得します。呼び出されたコンストラクタは、認証情報プロバイダチェーンから認証情報を取得します。このプロセスの詳細については、AWS SDK for Javaの「チュートリアル: IAM ロールと AWS SDK for Java を使用してアクセスを付与する」を参照してください。
AWS 認証情報の詳細については、AWS 全般のリファレンスの「AWS セキュリティ認証情報」を参照してください。
private static AWSSupportClient createClient() { AWSSupportClient client = new AWSSupportClient(); client.setEndpoint("https://support.us-east-1.amazonaws.com"); return client; }
Amazon Web Services と問題の重要度レベルの検出
AWS Support Java クライアントは、CreateCaseRequest
にプログラミングを使用してケースを送信するための AWS Support タイプを提供します。CreateCaseRequest
構造には、リクエストパラメータが入力され、createClient
インスタンスの AWSSupportClient
メソッドに渡されます。これらのパラメータには AWS サービスを指定するコードが含まれ、大文字と小文字が区別されます。
以下の Java コードスニペットは、AWS Support DescribeServices アクションと DescribeSeverityLevel オペレーションの呼び出しを示しています。
// 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 Support サービスに適用される AWSカテゴリのリストを返します。これらのカテゴリは、CreateCase オペレーションを使用してサポートケースを開くためにも使用されます。これらの値は AWS Supportサイトからも取得できますが、AWS Supportサービスは常にこの情報の最新版を返します。
添付セットの作成
ケースにファイルを添付するには、ケースを作成する前に添付セットに添付を追加する必要があります。1 つの添付ファイルセットに最大 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
– 以降のコミュニケーションのコピーを受信する E メールアドレスのリスト。 -
CommunicationBody
– 最初のケース送信の本文のテキスト。 -
Subject
– サポートケースのタイトル。 -
SeverityCode
の呼び出しによって返された値の 1 つ。DescribeSeverityLevels
-
AttachmentSetId
– (オプション) ケースに含まれる添付ファイルのセットの ID。AddAttachmentsToSet
操作により ID が返されます。
次の Java コードスニペットは、コマンドラインから各ケース作成パラメータの値を収集します。次に、CreateCaseRequest
インスタンスが入力され、AWS Support インスタンスの createCase
メソッドを呼び出して AWSSupportClient
に渡します。呼び出しが完了すると、AWS Support CaseId
値が以下の形式で返されます。
case-123456789012-muen-2012-74a757cd8cf7558a
AWS Support CaseId
と DisplayId
のフィールドがあります。DisplayId
フィールドは AWS Supportサイトに表示されるケース番号に対応します。CaseId
フィールドは、プログラミングによる AWS Supportサービスとの交信に使用されます。2 つのフィールドは、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 には、この通信文を取得するための DescribeCommunications と DescribeAttachment のオペレーション、およびケースを更新するための AddAttachmentsToSet と AddCommunicationToCase のオペレーションが用意されています。これらのアクションでは、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 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
は、サポートケースから、直近の 5 つのコミュニケーションを返します。また、DescribeCommunications
は CaseId
値のリストを取得し、1 回の呼び出しで複数のケースのコミュニケーションを取得できます。
すべてのサポートケース情報の取得
DescribeCases オペレーションを呼び出すことによって、AWS Supportケースに関連するすべての情報を取得できます。DescribeCasesRequest
データ型に、ClientId
要求が正常に返されたときに、各ケースによって返される createCase
値のリストを入力します。
次の Java コードスニペットは、コンソールから CaseId
値を受け取り、DescribeCases
オペレーションで使用するために DescribeCasesRequest
インスタンスを入力します。便宜性のためにプライベート 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()); }
AWS Support API のサービスクォータ
次の表に AWS Support API の現在のクォータを示します。
リソース |
デフォルト値 |
---|---|
作成できる AWS Support ケースの最大数。 |
1 時間あたり 10 |
1 秒あたりに実行できる AWS Support API オペレーションの最大数。 |
5 |
1 秒あたりに実行できる AWS Trusted Advisor API オペレーションの最大数。 |
100 |