Menjelaskan AWS Support komunikasi untuk kasus menggunakan AWS SDK - AWSContoh Kode SDK

Ada lebih banyak contoh AWS SDK yang tersedia di repo Contoh SDK AWS Doc. GitHub

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Menjelaskan AWS Support komunikasi untuk kasus menggunakan AWS SDK

Contoh kode berikut menunjukkan bagaimana menggambarkan AWS Support komunikasi untuk suatu kasus.

Contoh-contoh tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan di dalam konteks. Anda dapat melihat tindakan ini dalam konteks pada contoh kode berikut:

.NET
AWS SDK for .NET
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode 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; }
CLI
AWS CLI

Untuk menggambarkan komunikasi terbaru untuk suatu kasus

describe-communicationsContoh berikut mengembalikan komunikasi terbaru untuk kasus dukungan yang ditentukan di AWS akun Anda.

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

Output:

{ "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==" }

Untuk informasi selengkapnya, lihat Manajemen kasus di AWSSupport User Guide.

Java
SDK for Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode 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 ""; }
JavaScript
SDK untuk JavaScript (v3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode 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); } };
Kotlin
SDK for Kotlin
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode 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 "" }
Python
SDK for Python (Boto3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode 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