다음을 사용하는 S3 글레이셔 예제 AWS SDK for .NET - AWS SDK 코드 예제

AWS 문서 AWS SDK 예제 리포지토리에 더 많은 SDK 예제가 있습니다. GitHub

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

다음을 사용하는 S3 글레이셔 예제 AWS SDK for .NET

다음 코드 예제는 S3 Glacier와 AWS SDK for .NET 함께 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여줍니다.

작업은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 개별 서비스 함수를 호출하는 방법을 보여 주며 관련 시나리오와 교차 서비스 예시에서 컨텍스트에 맞는 작업을 볼 수 있습니다.

시나리오는 동일한 서비스 내에서 여러 함수를 호출하여 특정 태스크를 수행하는 방법을 보여주는 코드 예시입니다.

각 예제에는 GitHub 컨텍스트에서 코드를 설정하고 실행하는 방법에 대한 지침을 찾을 수 있는 링크가 포함되어 있습니다.

시작하기

다음 코드 예시에서는 Amazon S3 Glacier 사용을 시작하는 방법을 보여줍니다.

AWS SDK for .NET
참고

자세한 내용은 여기를 참조하십시오 GitHub. AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

using Amazon.Glacier; using Amazon.Glacier.Model; namespace GlacierActions; public static class HelloGlacier { static async Task Main() { var glacierService = new AmazonGlacierClient(); Console.WriteLine("Hello Amazon Glacier!"); Console.WriteLine("Let's list your Glacier vaults:"); // You can use await and any of the async methods to get a response. // Let's get the vaults using a paginator. var glacierVaultPaginator = glacierService.Paginators.ListVaults( new ListVaultsRequest { AccountId = "-" }); await foreach (var vault in glacierVaultPaginator.VaultList) { Console.WriteLine($"{vault.CreationDate}:{vault.VaultName}, ARN:{vault.VaultARN}"); } } }
  • API 세부 정보는 AWS SDK for .NET API ListVaults참조를 참조하십시오.

주제

작업

다음 코드 예시에서는 AddTagsToVault을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

자세한 내용은 에서 확인할 수 GitHub 있습니다. AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Add tags to the items in an Amazon S3 Glacier vault. /// </summary> /// <param name="vaultName">The name of the vault to add tags to.</param> /// <param name="key">The name of the object to tag.</param> /// <param name="value">The tag value to add.</param> /// <returns>A Boolean value indicating the success of the action.</returns> public async Task<bool> AddTagsToVaultAsync(string vaultName, string key, string value) { var request = new AddTagsToVaultRequest { Tags = new Dictionary<string, string> { { key, value }, }, AccountId = "-", VaultName = vaultName, }; var response = await _glacierService.AddTagsToVaultAsync(request); return response.HttpStatusCode == HttpStatusCode.NoContent; }
  • API 세부 정보는 AWS SDK for .NET API AddTagsToVault참조를 참조하십시오.

다음 코드 예시에서는 CreateVault을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

자세한 내용은 에서 확인할 수 GitHub 있습니다. AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Create an Amazon S3 Glacier vault. /// </summary> /// <param name="vaultName">The name of the vault to create.</param> /// <returns>A Boolean value indicating the success of the action.</returns> public async Task<bool> CreateVaultAsync(string vaultName) { var request = new CreateVaultRequest { // Setting the AccountId to "-" means that // the account associated with the current // account will be used. AccountId = "-", VaultName = vaultName, }; var response = await _glacierService.CreateVaultAsync(request); Console.WriteLine($"Created {vaultName} at: {response.Location}"); return response.HttpStatusCode == HttpStatusCode.Created; }
  • API 세부 정보는 AWS SDK for .NET API CreateVault참조를 참조하십시오.

다음 코드 예시에서는 DescribeVault을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

자세한 내용은 에서 확인할 수 GitHub 있습니다. AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Describe an Amazon S3 Glacier vault. /// </summary> /// <param name="vaultName">The name of the vault to describe.</param> /// <returns>The Amazon Resource Name (ARN) of the vault.</returns> public async Task<string> DescribeVaultAsync(string vaultName) { var request = new DescribeVaultRequest { AccountId = "-", VaultName = vaultName, }; var response = await _glacierService.DescribeVaultAsync(request); // Display the information about the vault. Console.WriteLine($"{response.VaultName}\tARN: {response.VaultARN}"); Console.WriteLine($"Created on: {response.CreationDate}\tNumber of Archives: {response.NumberOfArchives}\tSize (in bytes): {response.SizeInBytes}"); if (response.LastInventoryDate != DateTime.MinValue) { Console.WriteLine($"Last inventory: {response.LastInventoryDate}"); } return response.VaultARN; }
  • API 세부 정보는 AWS SDK for .NET API DescribeVault참조를 참조하십시오.

다음 코드 예시에서는 InitiateJob을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

자세한 내용은 에서 확인할 수 GitHub 있습니다. AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

저장소에서 아카이브를 검색하세요. 이 예제에서는 ArchiveTransferManager 클래스를 사용합니다. API 세부 정보는 을 참조하십시오 ArchiveTransferManager.

/// <summary> /// Download an archive from an Amazon S3 Glacier vault using the Archive /// Transfer Manager. /// </summary> /// <param name="vaultName">The name of the vault containing the object.</param> /// <param name="archiveId">The Id of the archive to download.</param> /// <param name="localFilePath">The local directory where the file will /// be stored after download.</param> /// <returns>Async Task.</returns> public async Task<bool> DownloadArchiveWithArchiveManagerAsync(string vaultName, string archiveId, string localFilePath) { try { var manager = new ArchiveTransferManager(_glacierService); var options = new DownloadOptions { StreamTransferProgress = Progress!, }; // Download an archive. Console.WriteLine("Initiating the archive retrieval job and then polling SQS queue for the archive to be available."); Console.WriteLine("When the archive is available, downloading will begin."); await manager.DownloadAsync(vaultName, archiveId, localFilePath, options); return true; } catch (AmazonGlacierException ex) { Console.WriteLine(ex.Message); return false; } } /// <summary> /// Event handler to track the progress of the Archive Transfer Manager. /// </summary> /// <param name="sender">The object that raised the event.</param> /// <param name="args">The argument values from the object that raised the /// event.</param> static void Progress(object sender, StreamTransferProgressArgs args) { if (args.PercentDone != _currentPercentage) { _currentPercentage = args.PercentDone; Console.WriteLine($"Downloaded {_currentPercentage}%"); } }
  • API 세부 정보는 AWS SDK for .NET API InitiateJob참조를 참조하십시오.

다음 코드 예시에서는 ListJobs을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

자세한 내용은 에서 확인할 수 GitHub 있습니다. AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// List Amazon S3 Glacier jobs. /// </summary> /// <param name="vaultName">The name of the vault to list jobs for.</param> /// <returns>A list of Amazon S3 Glacier jobs.</returns> public async Task<List<GlacierJobDescription>> ListJobsAsync(string vaultName) { var request = new ListJobsRequest { // Using a hyphen "-" for the Account Id will // cause the SDK to use the Account Id associated // with the current account. AccountId = "-", VaultName = vaultName, }; var response = await _glacierService.ListJobsAsync(request); return response.JobList; }
  • API 세부 정보는 AWS SDK for .NET API ListJobs참조를 참조하십시오.

다음 코드 예시에서는 ListTagsForVault을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

자세한 내용은 에서 확인할 수 GitHub 있습니다. AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// List tags for an Amazon S3 Glacier vault. /// </summary> /// <param name="vaultName">The name of the vault to list tags for.</param> /// <returns>A dictionary listing the tags attached to each object in the /// vault and its tags.</returns> public async Task<Dictionary<string, string>> ListTagsForVaultAsync(string vaultName) { var request = new ListTagsForVaultRequest { // Using a hyphen "-" for the Account Id will // cause the SDK to use the Account Id associated // with the default user. AccountId = "-", VaultName = vaultName, }; var response = await _glacierService.ListTagsForVaultAsync(request); return response.Tags; }
  • API 세부 정보는 AWS SDK for .NET API ListTagsForVault참조를 참조하십시오.

다음 코드 예시에서는 ListVaults을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

자세한 내용은 에서 확인할 수 GitHub 있습니다. AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// List the Amazon S3 Glacier vaults associated with the current account. /// </summary> /// <returns>A list containing information about each vault.</returns> public async Task<List<DescribeVaultOutput>> ListVaultsAsync() { var glacierVaultPaginator = _glacierService.Paginators.ListVaults( new ListVaultsRequest { AccountId = "-" }); var vaultList = new List<DescribeVaultOutput>(); await foreach (var vault in glacierVaultPaginator.VaultList) { vaultList.Add(vault); } return vaultList; }
  • API 세부 정보는 AWS SDK for .NET API ListVaults참조를 참조하십시오.

다음 코드 예시에서는 UploadArchive을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

자세한 내용은 에서 확인할 수 GitHub 있습니다. AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Upload an object to an Amazon S3 Glacier vault. /// </summary> /// <param name="vaultName">The name of the Amazon S3 Glacier vault to upload /// the archive to.</param> /// <param name="archiveFilePath">The file path of the archive to upload to the vault.</param> /// <returns>A Boolean value indicating the success of the action.</returns> public async Task<string> UploadArchiveWithArchiveManager(string vaultName, string archiveFilePath) { try { var manager = new ArchiveTransferManager(_glacierService); // Upload an archive. var response = await manager.UploadAsync(vaultName, "upload archive test", archiveFilePath); return response.ArchiveId; } catch (AmazonGlacierException ex) { Console.WriteLine(ex.Message); return string.Empty; } }
  • API 세부 정보는 AWS SDK for .NET API UploadArchive참조를 참조하십시오.