Utilizzare DescribeAttachment con un o AWS SDK CLI - Esempi di codice dell'AWS SDK

Ci sono altri AWS SDK esempi disponibili nel repository AWS Doc SDK Examples GitHub .

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Utilizzare DescribeAttachment con un o AWS SDK CLI

I seguenti esempi di codice mostrano come utilizzareDescribeAttachment.

Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:

.NET
AWS SDK for .NET
Nota

C'è altro da fare GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/// <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; }
CLI
AWS CLI

Per descrivere un allegato

L'describe-attachmentesempio seguente restituisce informazioni sull'allegato con l'ID specificato.

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

Output:

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

Per ulteriori informazioni, consulta la sezione Gestione dei casi nella AWS Support User Guide.

Java
SDKper Java 2.x
Nota

C'è di più su. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

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); } }
JavaScript
SDKper JavaScript (v3)
Nota

C'è di più su. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

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); } };
Kotlin
SDKper Kotlin
Nota

c'è altro da fare. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

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}") } }
Python
SDKper Python (Boto3)
Nota

C'è di più su. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice 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_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