Halaman ini hanya untuk pelanggan lama layanan Amazon Glacier menggunakan Vaults dan REST API asli dari 2012.
Jika Anda mencari solusi penyimpanan arsip, sebaiknya gunakan kelas penyimpanan Amazon Glacier di Amazon S3, S3 Glacier Instant Retrieval, S3 Glacier Flexible Retrieval, dan S3 Glacier Deep Archive. Untuk mempelajari lebih lanjut tentang opsi penyimpanan ini, lihat kelas penyimpanan Amazon Glacier
Amazon Glacier (layanan berbasis brankas mandiri asli) tidak akan lagi menerima pelanggan baru mulai 15 Desember 2025, tanpa berdampak pada pelanggan yang sudah ada. Amazon Glacier adalah layanan mandiri dengan miliknya APIs sendiri yang menyimpan data di brankas dan berbeda dari Amazon S3 dan kelas penyimpanan Amazon S3 Glacier. Data Anda yang ada akan tetap aman dan dapat diakses di Amazon Glacier tanpa batas waktu. Tidak diperlukan migrasi. Untuk penyimpanan arsip jangka panjang berbiaya rendah, AWS rekomendasikan kelas penyimpanan Amazon S3 Glacier
Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Mengunduh Arsip di Amazon Glacier Menggunakan AWS SDK untuk .NET
Baik tingkat tinggi dan tingkat rendah yang APIs disediakan oleh Amazon SDK untuk.NET menyediakan metode untuk mengunduh arsip.
Topik
Mengunduh Arsip Menggunakan API Tingkat Tinggi dari AWS SDK untuk .NET
Kelas ArchiveTransferManager dari API tingkat tinggi menyediakan metode Download yang dapat Anda gunakan untuk mengunduh arsip.
penting
Kelas ArchiveTransferManager membuat topik Amazon Simple Notification Service (Amazon SNS) dan antrean Amazon Simple Queue Service (Amazon SQS) yang berlangganan topik tersebut. Kelas tersebut selanjutnya memulai tugas pengambilan arsip dan melakukan polling antrean untuk arsip yang akan tersedia. Ketika arsip tersedia, unduhan dimulai. Untuk informasi tentang waktu pengambilan, lihat Opsi Pengambilan Arsip
Contoh: Mengunduh Arsip Menggunakan API Tingkat Tinggi AWS SDK untuk .NET
Contoh kode C# berikut mengunduh arsip dari vault (examplevault) di Wilayah US West (Oregon).
Untuk step-by-step petunjuk tentang cara menjalankan contoh ini, lihatMenjalankan Contoh Kode. Anda perlu memperbarui kode seperti yang ditunjukkan dengan ID arsip yang ada dan jalur file lokal tempat Anda ingin menyimpan arsip yang diunduh.
using System; using Amazon.Glacier; using Amazon.Glacier.Transfer; using Amazon.Runtime; namespace glacier.amazon.com.rproxy.govskope.ca.docsamples { class ArchiveDownloadHighLevel { static string vaultName = "examplevault"; static string archiveId = "*** Provide archive ID ***"; static string downloadFilePath = "*** Provide the file name and path to where to store the download ***"; public static void Main(string[] args) { try { var manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USWest2); var options = new DownloadOptions(); options.StreamTransferProgress += ArchiveDownloadHighLevel.progress; // Download an archive. Console.WriteLine("Intiating the archive retrieval job and then polling SQS queue for the archive to be available."); Console.WriteLine("Once the archive is available, downloading will begin."); manager.Download(vaultName, archiveId, downloadFilePath, options); 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); } Console.WriteLine("To continue, press Enter"); Console.ReadKey(); } static int currentPercentage = -1; static void progress(object sender, StreamTransferProgressArgs args) { if (args.PercentDone != currentPercentage) { currentPercentage = args.PercentDone; Console.WriteLine("Downloaded {0}%", args.PercentDone); } } } }
Mengunduh Arsip Menggunakan API Tingkat Rendah dari AWS SDK untuk .NET
Berikut ini adalah langkah-langkah untuk mengunduh arsip Amazon Glacier (Amazon Glacier) menggunakan API tingkat rendah. AWS SDK untuk .NET
-
Buat instans dari kelas
AmazonGlacierClient(klien).Anda perlu menentukan AWS Wilayah dari mana Anda ingin mengunduh arsip. Semua operasi yang Anda lakukan menggunakan klien ini berlaku untuk AWS Wilayah tersebut.
-
Mulai tugas
archive-retrievaldengan menjalankan metodeInitiateJob.Anda memberikan informasi pekerjaan, seperti ID arsip arsip yang ingin Anda unduh dan topik Amazon SNS opsional yang Anda inginkan Amazon Glacier untuk memposting pesan penyelesaian pekerjaan, dengan membuat instance kelas.
InitiateJobRequestAmazon Glacier mengembalikan ID pekerjaan sebagai tanggapan. Respons tersedia dalam instans dari kelasInitiateJobResponse.AmazonGlacierClient client; client = new AmazonGlacierClient(Amazon.RegionEndpoint.USWest2); InitiateJobRequest initJobRequest = new InitiateJobRequest() { VaultName = vaultName, JobParameters = new JobParameters() { Type = "archive-retrieval", ArchiveId = "*** Provide archive id ***", SNSTopic = "*** Provide Amazon SNS topic ARN ***", } }; InitiateJobResponse initJobResponse = client.InitiateJob(initJobRequest); string jobId = initJobResponse.JobId;Anda dapat secara opsional menentukan rentang byte untuk meminta Amazon Glacier untuk menyiapkan hanya sebagian dari arsip seperti yang ditunjukkan dalam permintaan berikut. Permintaan menentukan Amazon Glacier untuk menyiapkan hanya 1 MB hingga 2 MB bagian arsip.
AmazonGlacierClient client; client = new AmazonGlacierClient(Amazon.RegionEndpoint.USWest2); InitiateJobRequest initJobRequest = new InitiateJobRequest() { VaultName = vaultName, JobParameters = new JobParameters() { Type = "archive-retrieval", ArchiveId = "*** Provide archive id ***", SNSTopic = "*** Provide Amazon SNS topic ARN ***", } }; // Specify byte range. int ONE_MEG = 1048576; initJobRequest.JobParameters.RetrievalByteRange = string.Format("{0}-{1}", ONE_MEG, 2 * ONE_MEG -1); InitiateJobResponse initJobResponse = client.InitiateJob(initJobRequest); string jobId = initJobResponse.JobId; -
Tunggu hingga tugas selesai.
Anda harus menunggu hingga output tugas siap diunduh. Jika Anda telah menyetel konfigurasi notifikasi di vault yang mengidentifikasi topik Amazon Simple Notification Service (Amazon SNS) atau menetapkan topik Amazon SNS saat memulai pekerjaan, Amazon Glacier akan mengirimkan pesan ke topik tersebut setelah menyelesaikan pekerjaan. Contoh kode yang diberikan di bagian berikut menggunakan Amazon SNS untuk Amazon Glacier untuk mempublikasikan pesan.
Anda juga dapat melakukan polling Amazon Glacier dengan memanggil
DescribeJobmetode untuk menentukan status penyelesaian pekerjaan. Meskipun, menggunakan topik Amazon SNS untuk notifikasi adalah pendekatan yang disarankan. -
Unduh output tugas (data arsip) dengan menjalankan metode
GetJobOutput.Anda memberikan informasi permintaan seperti ID tugas dan nama vault dengan membuat instans dari kelas
GetJobOutputRequest. Output yang dikembalikan Amazon Glacier tersedia di objek.GetJobOutputResponseGetJobOutputRequest 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); } }Potongan kode sebelumnya mengunduh seluruh output tugas. Anda secara opsional dapat mengambil hanya sebagian output, atau mengunduh seluruh output dalam potongan yang lebih kecil dengan menentukan rentang byte di
GetJobOutputRequestAnda.GetJobOutputRequest getJobOutputRequest = new GetJobOutputRequest() { JobId = jobId, VaultName = vaultName }; getJobOutputRequest.SetRange(0, 1048575); // Download only the first 1 MB chunk of the output.Menanggapi
GetJobOutputpanggilan Anda, Amazon Glacier mengembalikan checksum bagian data yang Anda unduh, jika kondisi tertentu terpenuhi. Untuk informasi selengkapnya, lihat Menerima Checksum Saat Mengunduh Data.Untuk memverifikasi tidak ada kesalahan dalam unduhan, Anda kemudian dapat menghitung checksum di sisi klien dan membandingkannya dengan checksum Amazon Glacier yang dikirim dalam respons.
Untuk pekerjaan pengambilan arsip dengan rentang opsional yang ditentukan, ketika Anda mendapatkan deskripsi pekerjaan, itu termasuk checksum dari rentang yang Anda ambil (SHA256TreeHash) .Anda dapat menggunakan nilai ini untuk memverifikasi lebih lanjut keakuratan seluruh rentang byte yang kemudian Anda unduh. Misalnya, jika Anda memulai tugas untuk mengambil rentang arsip hash pohon selaras, lalu mengunduh output dalam potongan sehingga masing-masing permintaan
GetJobOutputAnda mengembalikan checksum, Anda dapat menghitung checksum setiap bagian yang Anda unduh di sisi klien, lalu menghitung hash pohon. Anda dapat membandingkannya dengan pengembalian Amazon Glacier checksum sebagai tanggapan atas permintaan pekerjaan deskripsikan Anda untuk memverifikasi bahwa seluruh rentang byte yang telah Anda unduh sama dengan rentang byte yang disimpan di Amazon Glacier.Untuk contoh pekerjaan, lihat Contoh 2: Mengambil Arsip Menggunakan API Tingkat Rendah dari AWS SDK untuk .NET—Download Output in Chunks.
Contoh 1: Mengambil Arsip Menggunakan API Tingkat Rendah AWS SDK untuk .NET
Contoh kode C# berikut mengunduh arsip dari vault yang ditentukan. Setelah tugas selesai, contoh mengunduh seluruh output dalam satu panggilan GetJobOutput. Untuk contoh mengunduh output dalam potongan, lihat Contoh 2: Mengambil Arsip Menggunakan API Tingkat Rendah dari AWS SDK untuk .NET—Download Output in Chunks.
Contoh tersebut melakukan tugas-tugas berikut:
-
Menyiapkan topik Amazon Simple Notification Service (Amazon SNS)
Amazon Glacier mengirimkan pemberitahuan ke topik ini setelah menyelesaikan pekerjaan.
Menyiapkan antrean Amazon Simple Queue Service (Amazon SQS).
Contoh melampirkan kebijakan ke antrean untuk mengizinkan topik Amazon SNS mengirim pesan.
Memulai tugas untuk mengunduh arsip yang ditentukan.
Dalam permintaan pekerjaan, contoh menentukan topik Amazon SNS sehingga Amazon Glacier dapat mengirim pesan setelah menyelesaikan pekerjaan.
Memeriksa antrean Amazon SQS secara berkala untuk pesan.
Jika ada pesan, urai JSON dan periksa apakah tugas berhasil diselesaikan. Jika ya, unduh arsipnya. Contoh kode menggunakan pustaka JSON.NET (lihat JSON.NET
) untuk mengurai JSON. Membersihkan dengan menghapus topik Amazon SNS dan antrean Amazon SQS yang dibuat.
using System; using System.Collections.Generic; using System.IO; using System.Threading; using Amazon.Glacier; using Amazon.Glacier.Model; 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 ArchiveDownloadLowLevelUsingSNSSQS { static string topicArn; static string queueUrl; static string queueArn; static string vaultName = "*** Provide vault name ***"; static string archiveID = "*** Provide archive ID ***"; static string fileName = "*** Provide the file name and path to where to store downloaded archive ***"; static AmazonSimpleNotificationServiceClient snsClient; static AmazonSQSClient sqsClient; const string SQS_POLICY = "{" + " \"Version\" : \"2012-10-17\",&TCX5-2025-waiver;" + " \"Statement\" : [" + " {" + " \"Sid\" : \"sns-rule\"," + " \"Effect\" : \"Allow\"," + " \"Principal\" : {\"Service\" : \"sns.amazonaws.com\" }," + " \"Action\" : \"sqs:SendMessage\"," + " \"Resource\" : \"{QueueArn}\"," + " \"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("Retrieving..."); RetrieveArchive(client); } Console.WriteLine("Operations successful. 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() { snsClient = new AmazonSimpleNotificationServiceClient(Amazon.RegionEndpoint.USWest2); sqsClient = new AmazonSQSClient(Amazon.RegionEndpoint.USWest2); long ticks = DateTime.Now.Ticks; 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 policy to the queue so SNS can send messages to the queue. var policy = SQS_POLICY.Replace("{TopicArn}", topicArn).Replace("{QueueArn}", queueArn); sqsClient.SetQueueAttributes(new SetQueueAttributesRequest() { QueueUrl = queueUrl, Attributes = new Dictionary<string, string> { { QueueAttributeName.Policy, policy } } }); } static void RetrieveArchive(AmazonGlacierClient client) { // Initiate job. InitiateJobRequest initJobRequest = new InitiateJobRequest() { VaultName = vaultName, JobParameters = new JobParameters() { Type = "archive-retrieval", ArchiveId = archiveID, Description = "This job is to download archive.", SNSTopic = topicArn, } }; InitiateJobResponse initJobResponse = client.InitiateJob(initJobRequest); string jobId = initJobResponse.JobId; // Check queue for a message and if job completed successfully, download archive. 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 archive."); 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); } } } }
Contoh 2: Mengambil Arsip Menggunakan API Tingkat Rendah dari AWS SDK untuk .NET—Download Output in Chunks
Contoh kode C # berikut mengambil arsip dari Amazon Glacier. Contoh kode mengunduh output tugas dalam potongan dengan menentukan rentang byte dalam objek GetJobOutputRequest.
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; using System.Collections.Specialized; namespace glacier.amazon.com.rproxy.govskope.ca.docsamples { class ArchiveDownloadLowLevelUsingSQLSNSOutputUsingRange { static string topicArn; static string queueUrl; static string queueArn; static string vaultName = "*** Provide vault name ***"; static string archiveId = "*** Provide archive ID ***"; static string fileName = "*** Provide the file name and path to where to store downloaded archive ***"; 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("Download archive"); DownloadAnArchive(archiveId, client); } Console.WriteLine("Operations successful. 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 DownloadAnArchive(string archiveId, AmazonGlacierClient client) { // Initiate job. InitiateJobRequest initJobRequest = new InitiateJobRequest() { VaultName = vaultName, JobParameters = new JobParameters() { Type = "archive-retrieval", ArchiveId = archiveId, Description = "This job is to download the archive.", SNSTopic = topicArn, } }; InitiateJobResponse initJobResponse = client.InitiateJob(initJobRequest); string jobId = initJobResponse.JobId; // Check queue for a message and if job completed successfully, download archive. ProcessQueue(jobId, client); } private static void ProcessQueue(string jobId, AmazonGlacierClient client) { var 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)) { long archiveSize = Convert.ToInt64(fields["ArchiveSizeInBytes"]); Console.WriteLine("Downloading job output"); DownloadOutput(jobId, archiveSize, client); // This where we 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 archive."); jobDone = true; sqsClient.DeleteMessage(new DeleteMessageRequest() { QueueUrl = queueUrl, ReceiptHandle = message.ReceiptHandle }); } } private static void DownloadOutput(string jobId, long archiveSize, AmazonGlacierClient client) { long partSize = 4 * (long)Math.Pow(2, 20); // 4 MB. using (Stream fileToSave = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { long currentPosition = 0; do { GetJobOutputRequest getJobOutputRequest = new GetJobOutputRequest() { JobId = jobId, VaultName = vaultName }; long endPosition = currentPosition + partSize - 1; if (endPosition > archiveSize) endPosition = archiveSize; getJobOutputRequest.SetRange(currentPosition, endPosition); GetJobOutputResponse getJobOutputResponse = client.GetJobOutput(getJobOutputRequest); using (Stream webStream = getJobOutputResponse.Body) { CopyStream(webStream, fileToSave); } currentPosition += partSize; } while (currentPosition < archiveSize); } } 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); } } } }