를 사용하여 Amazon Glacier에서 볼트 인벤토리 다운로드 AWS SDK for .NET - Amazon Glacier

이 페이지는 볼트와 2012년의 원래 REST API를 사용하는 Amazon Glacier 서비스의 기존 고객에게만 해당됩니다.

아카이브 스토리지 솔루션을 찾고 있다면 Amazon Glacier Amazon S3, S3 Glacier Flexible Retrieval 및 S3S3 Glacier Deep Archive의 Amazon Glacier 스토리지 클래스를 사용하는 것이 좋습니다. 이러한 스토리지 옵션에 대한 자세한 내용은 Amazon Glacier 스토리지 클래스를 참조하세요.

Amazon Glacier(기존 독립 실행형 볼트 기반 서비스)는 2025년 12월 15일부터 기존 고객에게 영향을 주지 않고 더 이상 신규 고객을 받지 않습니다. Amazon Glacier는 데이터를 볼트에 저장하고 Amazon S3 및 Amazon S3 Glacier 스토리지 클래스와 구별되는 자체 APIs가 있는 독립 실행형 서비스입니다. 기존 데이터는 Amazon Glacier에서 무기한으로 안전하고 액세스할 수 있습니다. 마이그레이션이 필요하지 않습니다. 저비용 장기 아카이브 스토리지의 경우는 S3 버킷 기반 API, 전체 가용성, 저렴한 비용 및 서비스 통합을 통해 우수한 고객 경험을 제공하는 Amazon S3 Glacier 스토리지 클래스를 AWS 권장합니다. S3 APIs AWS 리전 AWS 향상된 기능을 원하는 경우 Amazon Glacier 볼트에서 Amazon S3 Glacier 스토리지 클래스로 데이터를 전송하기 위한 솔루션 지침을 사용하여 Amazon S3 Glacier 스토리지 클래스로 마이그레이션하는 것이 좋습니다. AWS Amazon Glacier Amazon S3

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

를 사용하여 Amazon Glacier에서 볼트 인벤토리 다운로드 AWS SDK for .NET

다음은 AWS SDK for .NET의 저레벨 API를 사용해 볼트 인벤토리를 가져오는 단계입니다. 고레벨 API는 볼트 인벤토리를 가져오도록 지원하지 않습니다.

  1. AmazonGlacierClient 클래스(클라이언트)의 인스턴스를 만듭니다.

    볼트가 있는 AWS 리전을 지정해야 합니다. 이 클라이언트를 사용하여 수행하는 모든 작업은 해당 AWS 리전에 적용됩니다.

  2. InitiateJob 메서드를 실행하여 인벤토리 가져오기 작업을 시작합니다.

    사용자는 InitiateJobRequest 객체에 작업 정보를 제공합니다. Amazon Glacier(Amazon Glacier)는 응답으로 작업 ID를 반환합니다. 이 응답은 InitiateJobResponse 클래스 인스턴스에서 사용할 수 있습니다.

    AmazonGlacierClient client; client = new AmazonGlacierClient(Amazon.RegionEndpoint.USWest2); InitiateJobRequest initJobRequest = new InitiateJobRequest() { VaultName = vaultName, JobParameters = new JobParameters() { Type = "inventory-retrieval", SNSTopic = "*** Provide Amazon SNS topic arn ***", } }; InitiateJobResponse initJobResponse = client.InitiateJob(initJobRequest); string jobId = initJobResponse.JobId;
  3. 작업이 완료될 때까지 기다립니다.

    작업 출력을 다운로드할 수 있을 때까지 기다려야 합니다. 볼트에서 Amazon Simple Notification Service(Amazon SNS) 주제를 식별하는 알림 구성을 설정했거나 작업을 시작할 때 Amazon SNS 주제를 지정한 경우 Amazon Glacier는 작업을 완료한 후 해당 주제에 메시지를 보냅니다. 다음 섹션에 제공된 코드 예제에서는 Amazon Glacier용 Amazon SNS를 사용하여 메시지를 게시합니다. Amazon Glacier

    DescribeJob 메서드를 호출하여 작업 완료 상태를 확인하여 Amazon Glacier를 폴링할 수도 있습니다. 그러나 Amazon SNS 토픽의 알림을 사용해 식별하는 방법을 권장합니다.

  4. GetJobOutput 메서드를 실행하여 작업 출력(볼트 인벤토리 데이터)을 다운로드합니다.

    GetJobOutputRequest 클래스 인스턴스를 생성하여 계정 ID, 볼트 이름 및 작업 ID 정보를 입력합니다. 계정 ID를 입력하지 않는 경우에는 요청 서명을 위해 입력하는 자격 증명과 연결되어 있는 계정 ID로 간주합니다. 자세한 내용은 Amazon Glacier AWS SDK for .NET 에서 사용 단원을 참조하십시오.

    Amazon Glacier가 반환하는 출력은 GetJobOutputResponse 객체에서 사용할 수 있습니다.

    GetJobOutputRequest getJobOutputRequest = new GetJobOutputRequest() { JobId = jobId, VaultName = vaultName }; GetJobOutputResponse getJobOutputResponse = client.GetJobOutput(getJobOutputRequest); using (Stream webStream = getJobOutputResponse.Body) { using (Stream fileToSave = File.OpenWrite(fileName)) { CopyStream(webStream, fileToSave); } }

    참고

    작업과 관련된 기본 REST API에 대한 자세한 내용은 작업 단원을 참조하십시오.

예:의 하위 수준 API를 사용하여 볼트 인벤토리 검색 AWS SDK for .NET

다음은 볼트를 지정하여 볼트 인벤토리를 가져오는 C# 코드 예제입니다.

이 예에서는 다음과 같은 작업을 수행합니다.

  • Amazon SNS 토픽을 설정합니다.

    Amazon Glacier는 작업을 완료한 후이 주제에 알림을 보냅니다.

  • Amazon SQS 대기열을 생성합니다.

    아래 예시는 Amazon SNS 토픽이 메시지를 게시할 수 있도록 여기에서 해당 대기열에 정책을 연결합니다.

  • 지정된 아카이브의 다운로드 작업을 시작합니다.

    작업 요청에서이 예제는 Amazon Glacier가 작업을 완료한 후 메시지를 보낼 수 있도록 Amazon SNS 주제를 지정합니다.

  • Amazon SQS 대기열의 메시지를 주기적으로 확인합니다.

    메시지가 있으면 JSON 구문을 분석하여 작업이 성공적으로 완료되었는지 확인합니다. 성공적으로 완료되었으면 아카이브를 다운로드합니다. 아래 코드 예제에서는 JSON.NET 라이브러리(JSON.NET 참조)를 사용하여 JSON 구분을 분석합니다.

  • 생성된 Amazon SNS 토픽과 Amazon SQS 대기열을 삭제하여 정리합니다.

using System; using System.Collections.Generic; using System.IO; using System.Threading; using Amazon.Glacier; using Amazon.Glacier.Model; using Amazon.Glacier.Transfer; using Amazon.Runtime; using Amazon.SimpleNotificationService; using Amazon.SimpleNotificationService.Model; using Amazon.SQS; using Amazon.SQS.Model; using Newtonsoft.Json; namespace glacier.amazon.com.rproxy.govskope.ca.docsamples { class VaultInventoryJobLowLevelUsingSNSSQS { static string topicArn; static string queueUrl; static string queueArn; static string vaultName = "*** Provide vault name ***"; static string fileName = "*** Provide file name and path where to store inventory ***"; static AmazonSimpleNotificationServiceClient snsClient; static AmazonSQSClient sqsClient; const string SQS_POLICY = "{" + " \"Version\" : \"2012-10-17\",&TCX5-2025-waiver;" + " \"Statement\" : [" + " {" + " \"Sid\" : \"sns-rule\"," + " \"Effect\" : \"Allow\"," + " \"Principal\" : {\"AWS\" : \"arn:aws:iam::123456789012:root\" }," + " \"Action\" : \"sqs:SendMessage\"," + " \"Resource\" : \"{QuernArn}\"," + " \"Condition\" : {" + " \"ArnLike\" : {" + " \"aws:SourceArn\" : \"{TopicArn}\"" + " }" + " }" + " }" + " ]" + "}"; public static void Main(string[] args) { AmazonGlacierClient client; try { using (client = new AmazonGlacierClient(Amazon.RegionEndpoint.USWest2)) { Console.WriteLine("Setup SNS topic and SQS queue."); SetupTopicAndQueue(); Console.WriteLine("To continue, press Enter"); Console.ReadKey(); Console.WriteLine("Retrieve Inventory List"); GetVaultInventory(client); } Console.WriteLine("Operations successful."); Console.WriteLine("To continue, press Enter"); Console.ReadKey(); } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } finally { // Delete SNS topic and SQS queue. snsClient.DeleteTopic(new DeleteTopicRequest() { TopicArn = topicArn }); sqsClient.DeleteQueue(new DeleteQueueRequest() { QueueUrl = queueUrl }); } } static void SetupTopicAndQueue() { long ticks = DateTime.Now.Ticks; // Setup SNS topic. snsClient = new AmazonSimpleNotificationServiceClient(Amazon.RegionEndpoint.USWest2); sqsClient = new AmazonSQSClient(Amazon.RegionEndpoint.USWest2); topicArn = snsClient.CreateTopic(new CreateTopicRequest { Name = "GlacierDownload-" + ticks }).TopicArn; Console.Write("topicArn: "); Console.WriteLine(topicArn); CreateQueueRequest createQueueRequest = new CreateQueueRequest(); createQueueRequest.QueueName = "GlacierDownload-" + ticks; CreateQueueResponse createQueueResponse = sqsClient.CreateQueue(createQueueRequest); queueUrl = createQueueResponse.QueueUrl; Console.Write("QueueURL: "); Console.WriteLine(queueUrl); GetQueueAttributesRequest getQueueAttributesRequest = new GetQueueAttributesRequest(); getQueueAttributesRequest.AttributeNames = new List<string> { "QueueArn" }; getQueueAttributesRequest.QueueUrl = queueUrl; GetQueueAttributesResponse response = sqsClient.GetQueueAttributes(getQueueAttributesRequest); queueArn = response.QueueARN; Console.Write("QueueArn: ");Console.WriteLine(queueArn); // Setup the Amazon SNS topic to publish to the SQS queue. snsClient.Subscribe(new SubscribeRequest() { Protocol = "sqs", Endpoint = queueArn, TopicArn = topicArn }); // Add the policy to the queue so SNS can send messages to the queue. var policy = SQS_POLICY.Replace("{TopicArn}", topicArn).Replace("{QuernArn}", queueArn); sqsClient.SetQueueAttributes(new SetQueueAttributesRequest() { QueueUrl = queueUrl, Attributes = new Dictionary<string, string> { { QueueAttributeName.Policy, policy } } }); } static void GetVaultInventory(AmazonGlacierClient client) { // Initiate job. InitiateJobRequest initJobRequest = new InitiateJobRequest() { VaultName = vaultName, JobParameters = new JobParameters() { Type = "inventory-retrieval", Description = "This job is to download a vault inventory.", SNSTopic = topicArn, } }; InitiateJobResponse initJobResponse = client.InitiateJob(initJobRequest); string jobId = initJobResponse.JobId; // Check queue for a message and if job completed successfully, download inventory. ProcessQueue(jobId, client); } private static void ProcessQueue(string jobId, AmazonGlacierClient client) { ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest() { QueueUrl = queueUrl, MaxNumberOfMessages = 1 }; bool jobDone = false; while (!jobDone) { Console.WriteLine("Poll SQS queue"); ReceiveMessageResponse receiveMessageResponse = sqsClient.ReceiveMessage(receiveMessageRequest); if (receiveMessageResponse.Messages.Count == 0) { Thread.Sleep(10000 * 60); continue; } Console.WriteLine("Got message"); Message message = receiveMessageResponse.Messages[0]; Dictionary<string, string> outerLayer = JsonConvert.DeserializeObject<Dictionary<string, string>>(message.Body); Dictionary<string, object> fields = JsonConvert.DeserializeObject<Dictionary<string, object>>(outerLayer["Message"]); string statusCode = fields["StatusCode"] as string; if (string.Equals(statusCode, GlacierUtils.JOB_STATUS_SUCCEEDED, StringComparison.InvariantCultureIgnoreCase)) { Console.WriteLine("Downloading job output"); DownloadOutput(jobId, client); // Save job output to the specified file location. } else if (string.Equals(statusCode, GlacierUtils.JOB_STATUS_FAILED, StringComparison.InvariantCultureIgnoreCase)) Console.WriteLine("Job failed... cannot download the inventory."); jobDone = true; sqsClient.DeleteMessage(new DeleteMessageRequest() { QueueUrl = queueUrl, ReceiptHandle = message.ReceiptHandle }); } } private static void DownloadOutput(string jobId, AmazonGlacierClient client) { GetJobOutputRequest getJobOutputRequest = new GetJobOutputRequest() { JobId = jobId, VaultName = vaultName }; GetJobOutputResponse getJobOutputResponse = client.GetJobOutput(getJobOutputRequest); using (Stream webStream = getJobOutputResponse.Body) { using (Stream fileToSave = File.OpenWrite(fileName)) { CopyStream(webStream, fileToSave); } } } public static void CopyStream(Stream input, Stream output) { byte[] buffer = new byte[65536]; int length; while ((length = input.Read(buffer, 0, buffer.Length)) > 0) { output.Write(buffer, 0, length); } } } }