使用 Amazon SDK 描述 Amazon Web Services Support 案例的附件 - Amazon Web Services Support
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Amazon SDK 描述 Amazon Web Services Support 案例的附件

以下代码示例演示了如何描述 Amazon Web Services Support 案例的附件。

操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:

.NET
Amazon SDK for .NET
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/// <summary> /// Get description of a specific attachment. /// </summary> /// <param name="attachmentId">Id of the attachment, usually fetched by describing the communications of a case.</param> /// <returns>The attachment object.</returns> public async Task<Attachment> DescribeAttachment(string attachmentId) { var response = await _amazonSupport.DescribeAttachmentAsync( new DescribeAttachmentRequest() { AttachmentId = attachmentId }); return response.Attachment; }
  • 有关 API 的详细信息,请参阅 Amazon SDK for .NET API 参考DescribeAttachment中的。

CLI
Amazon CLI

描述附件

以下 describe-attachment 示例返回有关带指定 ID 的附件的信息。

aws support describe-attachment \ --attachment-id "attachment-KBnjRNrePd9D6Jx0-Mm00xZuDEaL2JAj_0-gJv9qqDooTipsz3V1Nb19rCfkZneeQeDPgp8X1iVJyHH7UuhZDdNeqGoduZsPrAhyMakqlc60-iJjL5HqyYGiT1FG8EXAMPLE"

输出:

{ "attachment": { "fileName": "troubleshoot-screenshot.png", "data": "base64-blob" } }

有关更多信息,请参阅《Amazon Support 用户指南》中的案例管理

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeAttachment中的。

Java
适用于 Java 2.x 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

public static void describeAttachment(SupportClient supportClient, String attachId) { try { DescribeAttachmentRequest attachmentRequest = DescribeAttachmentRequest.builder() .attachmentId(attachId) .build(); DescribeAttachmentResponse response = supportClient.describeAttachment(attachmentRequest); System.out.println("The name of the file is " + response.attachment().fileName()); } catch (SupportException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } }
  • 有关 API 的详细信息,请参阅 Amazon SDK for Java 2.x API 参考DescribeAttachment中的。

JavaScript
适用于 JavaScript (v3) 的软件开发工具包
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

import { DescribeAttachmentCommand } from "@aws-sdk/client-support"; import { client } from "../libs/client.js"; export const main = async () => { try { // Get the metadata and content of an attachment. const response = await client.send( new DescribeAttachmentCommand({ // Set value to an existing attachment id. // Use DescribeCommunications or DescribeCases to find an attachment id. attachmentId: "ATTACHMENT_ID", }), ); console.log(response.attachment?.fileName); return response; } catch (err) { console.error(err); } };
  • 有关 API 的详细信息,请参阅 Amazon SDK for JavaScript API 参考DescribeAttachment中的。

Kotlin
适用于 Kotlin 的 SDK
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

suspend fun describeAttachment(attachId: String?) { val attachmentRequest = DescribeAttachmentRequest { attachmentId = attachId } SupportClient { region = "us-west-2" }.use { supportClient -> val response = supportClient.describeAttachment(attachmentRequest) println("The name of the file is ${response.attachment?.fileName}") } }
  • 有关 API 的详细信息,请参阅适用DescribeAttachment于 K otlin 的Amazon SDK API 参考

Python
SDK for Python (Boto3)
注意

还有更多相关信息 GitHub。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

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_attachment(self, attachment_id): """ Get information about an attachment by its attachmentID. :param attachment_id: The ID of the attachment. :return: The name of the attached file. """ try: response = self.support_client.describe_attachment( attachmentId=attachment_id ) attached_file = response["attachment"]["fileName"] 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 get attachment description. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return attached_file
  • 有关 API 的详细信息,请参阅适用DescribeAttachmentPython 的Amazon SDK (Boto3) API 参考

有关 S Amazon DK 开发者指南和代码示例的完整列表,请参阅将 Amazon Web Services Support 与 Amazon 开发工具包配合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。