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> /// 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 "en" (English) and "ja" (Japanese) 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 の詳細については、「 API リファレンスDescribeCases」の「」を参照してください。 AWS SDK for .NET

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 の詳細については、「 コマンドリファレンスDescribeCases」の「」を参照してください。 AWS CLI

Java
SDK for Java 2.x
注記

には他にもがあります 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 の詳細については、「 API リファレンスDescribeCases」の「」を参照してください。 AWS SDK for Java 2.x

JavaScript
SDK for JavaScript (v3)
注記

には他にもがあります 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 の詳細については、「 API リファレンスDescribeCases」の「」を参照してください。 AWS SDK for JavaScript

Kotlin
SDK for Kotlin
注記

には他にもがあります 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 の詳細については、DescribeCasesAWS「 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_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) API リファレンスの「」を参照してください。