DescribeCases 搭配 a AWS SDK 或 CLI 使用 - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

DescribeCases 搭配 a AWS SDK 或 CLI 使用

下列程式碼範例示範如何使用 DescribeCases

動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:

.NET
AWS SDK for .NET
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <summary> /// Get case details for a list of case ids, optionally with date filters. /// </summary> /// <param name="caseIds">The list of case IDs.</param> /// <param name="displayId">Optional display ID.</param> /// <param name="includeCommunication">True to include communication. Defaults to true.</param> /// <param name="includeResolvedCases">True to include resolved cases. Defaults to false.</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> /// <param name="language">Optional language support for your case. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <returns>A list of CaseDetails.</returns> public async Task<List<CaseDetails>> DescribeCases(List<string> caseIds, string? displayId = null, bool includeCommunication = true, bool includeResolvedCases = false, DateTime? afterTime = null, DateTime? beforeTime = null, string language = "en") { var results = new List<CaseDetails>(); var paginateCases = _amazonSupport.Paginators.DescribeCases( new DescribeCasesRequest() { CaseIdList = caseIds, DisplayId = displayId, IncludeCommunications = includeCommunication, IncludeResolvedCases = includeResolvedCases, AfterTime = afterTime?.ToString("s"), BeforeTime = beforeTime?.ToString("s"), Language = language }); // Get the entire list using the paginator. await foreach (var cases in paginateCases.Cases) { results.Add(cases); } return results; }
  • 如需 API 詳細資訊,請參閱 DescribeCases AWS SDK for .NET 參考中的 API

CLI
AWS CLI

描述案例

下列describe-cases範例會傳回您 AWS 帳戶中指定支援案例的相關資訊。

aws support describe-cases \ --display-id "1234567890" \ --after-time "2020-03-23T21:31:47.774Z" \ --include-resolved-cases \ --language "en" \ --no-include-communications \ --max-item 1

輸出:

{ "cases": [ { "status": "resolved", "ccEmailAddresses": [], "timeCreated": "2020-03-23T21:31:47.774Z", "caseId": "case-12345678910-2013-c4c1d2bf33c5cf47", "severityCode": "low", "language": "en", "categoryCode": "using-aws", "serviceCode": "general-info", "submittedBy": "myemail@example.com", "displayId": "1234567890", "subject": "Question about my account" } ] }

如需詳細資訊,請參閱 AWS 支援使用者指南中的案例管理

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeCases

Java
Java 2.x 的 SDK
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

public static void getOpenCase(SupportClient supportClient) { try { // Specify the start and end time. Instant now = Instant.now(); java.time.LocalDate.now(); Instant yesterday = now.minus(1, ChronoUnit.DAYS); DescribeCasesRequest describeCasesRequest = DescribeCasesRequest.builder() .maxResults(20) .afterTime(yesterday.toString()) .beforeTime(now.toString()) .build(); DescribeCasesResponse response = supportClient.describeCases(describeCasesRequest); List<CaseDetails> cases = response.cases(); for (CaseDetails sinCase : cases) { System.out.println("The case status is " + sinCase.status()); System.out.println("The case Id is " + sinCase.caseId()); System.out.println("The case subject is " + sinCase.subject()); } } catch (SupportException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } }
  • 如需 API 詳細資訊,請參閱 DescribeCases AWS SDK for Java 2.x 參考中的 API

JavaScript
SDK for JavaScript (v3)
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

import { DescribeCasesCommand } from "@aws-sdk/client-support"; import { client } from "../libs/client.js"; export const main = async () => { try { // Get all of the unresolved cases in your account. // Filter or expand results by providing parameters to the DescribeCasesCommand. 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/describecasescommandinput.html const response = await client.send(new DescribeCasesCommand({})); const caseIds = response.cases.map((supportCase) => supportCase.caseId); console.log(caseIds); return response; } catch (err) { console.error(err); } };
  • 如需 API 詳細資訊,請參閱 DescribeCases AWS SDK for JavaScript 參考中的 API

Kotlin
Kotlin 的 SDK
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

suspend fun getOpenCase() { // Specify the start and end time. val now = Instant.now() LocalDate.now() val yesterday = now.minus(1, ChronoUnit.DAYS) val describeCasesRequest = DescribeCasesRequest { maxResults = 20 afterTime = yesterday.toString() beforeTime = now.toString() } SupportClient { region = "us-west-2" }.use { supportClient -> val response = supportClient.describeCases(describeCasesRequest) response.cases?.forEach { sinCase -> println("The case status is ${sinCase.status}") println("The case Id is ${sinCase.caseId}") println("The case subject is ${sinCase.subject}") } } }
  • 如需 API 詳細資訊,請參閱 DescribeCases AWS for Kotlin SDK 參考中的 API

PowerShell
for PowerShell 工具

範例 1:傳回所有支援案例的詳細資訊。

Get-ASACase

範例 2:傳回自指定日期和時間以來所有支援案例的詳細資訊。

Get-ASACase -AfterTime "2013-09-10T03:06Z"

範例 3:傳回前 10 個支援案例的詳細資訊,包括已解決的案例。

Get-ASACase -MaxResult 10 -IncludeResolvedCases $true

範例 4:傳回單一指定支援案例的詳細資訊。

Get-ASACase -CaseIdList "case-12345678910-2013-c4c1d2bf33c5cf47"

範例 5:傳回指定支援案例的詳細資訊。

Get-ASACase -CaseIdList @("case-12345678910-2013-c4c1d2bf33c5cf47", "case-18929034710-2011-c4fdeabf33c5cf47")
  • 如需 API 詳細資訊,請參閱 AWS Tools for PowerShell Cmdlet 參考中的 DescribeCases

Python
Python 的 SDK (Boto3)
注意

還有更多 on 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_cases(self, after_time, before_time, resolved): """ Describe support cases over a period of time, optionally filtering by status. :param after_time: The start time to include for cases. :param before_time: The end time to include for cases. :param resolved: True to include resolved cases in the results, otherwise results are open cases. :return: The final status of the case. """ try: cases = [] paginator = self.support_client.get_paginator("describe_cases") for page in paginator.paginate( afterTime=after_time, beforeTime=before_time, includeResolvedCases=resolved, language="en", ): cases += page["cases"] 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 cases. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: if resolved: cases = filter(lambda case: case["status"] == "resolved", cases) return cases
  • 如需 API 詳細資訊,請參閱 DescribeCases AWS SDK for Python (Boto3) Word 參考中的 API