AWS SDK を使用してケースの AWS Support コミュニケーションについて説明する - AWS SDK コードサンプル

Doc AWS SDK Examples リポジトリには、他にも SDK の例があります。 AWS GitHub

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDK を使用してケースの AWS Support コミュニケーションについて説明する

次のコード例は、ケースの AWS Support コミュニケーションの説明方法を示しています。

アクション例は、より大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。次のコード例で、このアクションのコンテキストを確認できます。

.NET
AWS SDK for .NET
注記

には他にもがあります GitHub。用例一覧を検索し、AWS コードサンプルリポジトリでの設定と実行の方法を確認してください。

/// <summary> /// Describe the communications for a case, optionally with a date filter. /// </summary> /// <param name="caseId">The ID of the support case.</param> /// <param name="afterTime">The optional start date for a filtered search.</param> /// <param name="beforeTime">The optional end date for a filtered search.</param> /// <returns>The list of communications for the case.</returns> public async Task<List<Communication>> DescribeCommunications(string caseId, DateTime? afterTime = null, DateTime? beforeTime = null) { var results = new List<Communication>(); var paginateCommunications = _amazonSupport.Paginators.DescribeCommunications( new DescribeCommunicationsRequest() { CaseId = caseId, AfterTime = afterTime?.ToString("s"), BeforeTime = beforeTime?.ToString("s") }); // Get the entire list using the paginator. await foreach (var communications in paginateCommunications.Communications) { results.Add(communications); } return results; }
  • API の詳細については、「 API リファレンスDescribeCommunications」の「」を参照してください。 AWS SDK for .NET

CLI
AWS CLI

ケースの最新のコミュニケーションについて説明する

次の describe-communications の例では、AWS アカウント内の指定されたサポートケースの最新のコミュニケーションを返します。

aws support describe-communications \ --case-id "case-12345678910-2013-c4c1d2bf33c5cf47" \ --after-time "2020-03-23T21:31:47.774Z" \ --max-item 1

出力:

{ "communications": [ { "body": "I want to learn more about an AWS service.", "attachmentSet": [], "caseId": "case-12345678910-2013-c4c1d2bf33c5cf47", "timeCreated": "2020-05-12T23:12:35.000Z", "submittedBy": "Amazon Web Services" } ], "NextToken": "eyJuZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQEXAMPLE==" }

詳細については、「AWS サポートユーザーガイド」の「ケース管理」を参照してください。

  • API の詳細については、「 コマンドリファレンスDescribeCommunications」の「」を参照してください。 AWS CLI

Java
SDK for Java 2.x
注記

には他にもがあります GitHub。用例一覧を検索し、AWS コードサンプルリポジトリでの設定と実行の方法を確認してください。

public static String listCommunications(SupportClient supportClient, String caseId) { try { String attachId = null; DescribeCommunicationsRequest communicationsRequest = DescribeCommunicationsRequest.builder() .caseId(caseId) .maxResults(10) .build(); DescribeCommunicationsResponse response = supportClient.describeCommunications(communicationsRequest); List<Communication> communications = response.communications(); for (Communication comm : communications) { System.out.println("the body is: " + comm.body()); // Get the attachment id value. List<AttachmentDetails> attachments = comm.attachmentSet(); for (AttachmentDetails detail : attachments) { attachId = detail.attachmentId(); } } return attachId; } catch (SupportException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } return ""; }
  • API の詳細については、「 API リファレンスDescribeCommunications」の「」を参照してください。 AWS SDK for Java 2.x

JavaScript
SDK for JavaScript (v3)
注記

には他にもがあります GitHub。用例一覧を検索し、AWS コードサンプルリポジトリでの設定と実行の方法を確認してください。

import { DescribeCommunicationsCommand } from "@aws-sdk/client-support"; import { client } from "../libs/client.js"; export const main = async () => { try { // Get all communications for the support case. // Filter results by providing parameters to the DescribeCommunicationsCommand. Refer // to the TypeScript definition and the API doc for more information on possible parameters. // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-support/interfaces/describecommunicationscommandinput.html const response = await client.send( new DescribeCommunicationsCommand({ // Set value to an existing case id. caseId: "CASE_ID", }), ); const text = response.communications.map((item) => item.body).join("\n"); console.log(text); return response; } catch (err) { console.error(err); } };
  • API の詳細については、「 API リファレンスDescribeCommunications」の「」を参照してください。 AWS SDK for JavaScript

Kotlin
SDK for Kotlin
注記

には他にもがあります GitHub。用例一覧を検索し、AWS コードサンプルリポジトリでの設定と実行の方法を確認してください。

suspend fun listCommunications(caseIdVal: String?): String? { val communicationsRequest = DescribeCommunicationsRequest { caseId = caseIdVal maxResults = 10 } SupportClient { region = "us-west-2" }.use { supportClient -> val response = supportClient.describeCommunications(communicationsRequest) response.communications?.forEach { comm -> println("the body is: " + comm.body) comm.attachmentSet?.forEach { detail -> return detail.attachmentId } } } return "" }
  • API の詳細については、DescribeCommunicationsAWS「 SDK for Kotlin API リファレンス」の「」を参照してください。

Python
SDK for Python (Boto3)
注記

には他にもがあります GitHub。用例一覧を検索し、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_all_case_communications(self, case_id): """ Describe all the communications for a case using a paginator. :param case_id: The ID of the case. :return: The communications for the case. """ try: communications = [] paginator = self.support_client.get_paginator("describe_communications") for page in paginator.paginate(caseId=case_id): communications += page["communications"] 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 describe communications. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return communications
  • API の詳細については、 DescribeCommunications AWS SDK for Python (Boto3) API リファレンスの「」を参照してください。