AddAttachmentsToSetAWS SDKOR와 함께 사용 CLI - AWS Support

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

AddAttachmentsToSetAWS SDKOR와 함께 사용 CLI

다음 코드 예제는 AddAttachmentsToSet의 사용 방법을 보여 줍니다.

작업 예제는 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 다음 코드 예제에서는 컨텍스트 내에서 이 작업을 확인할 수 있습니다.

.NET
AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Add an attachment to a set, or create a new attachment set if one does not exist. /// </summary> /// <param name="data">The data for the attachment.</param> /// <param name="fileName">The file name for the attachment.</param> /// <param name="attachmentSetId">Optional setId for the attachment. Creates a new attachment set if empty.</param> /// <returns>The setId of the attachment.</returns> public async Task<string> AddAttachmentToSet(MemoryStream data, string fileName, string? attachmentSetId = null) { var response = await _amazonSupport.AddAttachmentsToSetAsync( new AddAttachmentsToSetRequest { AttachmentSetId = attachmentSetId, Attachments = new List<Attachment> { new Attachment { Data = data, FileName = fileName } } }); return response.AttachmentSetId; }
CLI
AWS CLI

세트에 첨부 파일 추가하기

다음 add-attachments-to-set 예시에서는 세트에 이미지를 추가한 다음 AWS 계정의 지원 사례에 대해 이 이미지를 지정할 수 있습니다.

aws support add-attachments-to-set \ --attachment-set-id "as-2f5a6faa2a4a1e600-mu-nk5xQlBr70-G1cUos5LZkd38KOAHZa9BMDVzNEXAMPLE" \ --attachments fileName=troubleshoot-screenshot.png,data=base64-encoded-string

출력:

{ "attachmentSetId": "as-2f5a6faa2a4a1e600-mu-nk5xQlBr70-G1cUos5LZkd38KOAHZa9BMDVzNEXAMPLE", "expiryTime": "2020-05-14T17:04:40.790+0000" }

자세한 내용은 AWS Support 사용 설명서의 사례 관리를 참조하세요.

Java
SDK자바 2.x의 경우
참고

더 많은 내용이 있습니다. GitHub AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

public static String addAttachment(SupportClient supportClient, String fileAttachment) { try { File myFile = new File(fileAttachment); InputStream sourceStream = new FileInputStream(myFile); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); Attachment attachment = Attachment.builder() .fileName(myFile.getName()) .data(sourceBytes) .build(); AddAttachmentsToSetRequest setRequest = AddAttachmentsToSetRequest.builder() .attachments(attachment) .build(); AddAttachmentsToSetResponse response = supportClient.addAttachmentsToSet(setRequest); return response.attachmentSetId(); } catch (SupportException | FileNotFoundException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } return ""; }
JavaScript
SDK JavaScript (v3) 에 대한
참고

더 많은 정보가 있습니다. GitHub AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

import { AddAttachmentsToSetCommand } from "@aws-sdk/client-support"; import { client } from "../libs/client.js"; export const main = async () => { try { // Create a new attachment set or add attachments to an existing set. // Provide an 'attachmentSetId' value to add attachments to an existing set. // Use AddCommunicationToCase or CreateCase to associate an attachment set with a support case. const response = await client.send( new AddAttachmentsToSetCommand({ // You can add up to three attachments per set. The size limit is 5 MB per attachment. attachments: [ { fileName: "example.txt", data: new TextEncoder().encode("some example text"), }, ], }), ); // Use this ID in AddCommunicationToCase or CreateCase. console.log(response.attachmentSetId); return response; } catch (err) { console.error(err); } };
Kotlin
SDK코틀린의 경우
참고

더 많은 정보가 있습니다. GitHub AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

suspend fun addAttachment(fileAttachment: String): String? { val myFile = File(fileAttachment) val sourceBytes = (File(fileAttachment).readBytes()) val attachmentVal = Attachment { fileName = myFile.name data = sourceBytes } val setRequest = AddAttachmentsToSetRequest { attachments = listOf(attachmentVal) } SupportClient { region = "us-west-2" }.use { supportClient -> val response = supportClient.addAttachmentsToSet(setRequest) return response.attachmentSetId } }
Python
SDK파이썬용 (보토3)
참고

더 많은 정보가 있습니다. 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 add_attachment_to_set(self): """ Add an attachment to a set, or create a new attachment set if one does not exist. :return: The attachment set ID. """ try: response = self.support_client.add_attachments_to_set( attachments=[ { "fileName": "attachment_file.txt", "data": b"This is a sample file for attachment to a support case.", } ] ) new_set_id = response["attachmentSetId"] 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 add attachment. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return new_set_id
  • 자세한 API AWS SDK내용은 Python (Boto3) API 참조를 참조하십시오 AddAttachmentsToSet.

AWS SDK개발자 가이드 및 코드 예제의 전체 목록은 을 참조하십시오. AWS SupportAWS SDK와 함께 사용 이 항목에는 시작하기 관련 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.