AWS SDK for .NET
Developer Guide

This documentation is for version 2.0 of the AWS SDK for .NET. For the latest version, see the AWS SDK for .NET Developer Guide for version 3.

Amazon Glacier Programming with the AWS SDK for .NET

The AWS SDK for .NET supports Amazon Glacier, which is a storage service optimized for infrequently used data, or "cold data." The service provides durable and extremely low-cost storage with security features for data archiving and backup. For more information, see Amazon Glacier.

The following information introduces you to the Amazon Glacier programming models in the the SDK.

Programming Models#

The the SDK provides three programming models for working with Amazon Glacier. These programming models are known as the low-level, high-level, and resource models. The following information describes these models, why you would want to use them, and how to use them.

Low-Level APIs#

The the SDK provides low-level APIs for programming with Amazon Glacier. These low-level APIs map closely the underlying REST API supported by Amazon Glacier. For each Amazon Glacier REST operation, the low-level APIs provide a corresponding method, a request object for you to provide request information, and a response object for you to process the Amazon Glacier response. The low-level APIs are the most complete implementation of the underlying Amazon Glacier operations.

The following example shows how to use the low-level APIs to list accessible vaults in Amazon Glacier:

// using Amazon.Glacier;
// using Amazon.Glacier.Model;

var client = new AmazonGlacierClient();
var request = new ListVaultsRequest();
var response = client.ListVaults(request);

foreach (var vault in response.VaultList)
{
  Console.WriteLine("Vault: {0}", vault.VaultName);
  Console.WriteLine("  Creation date: {0}", vault.CreationDate);
  Console.WriteLine("  Size in bytes: {0}", vault.SizeInBytes);
  Console.WriteLine("  Number of archives: {0}", vault.NumberOfArchives);
  
  try 
  {
    var requestNotifications = new GetVaultNotificationsRequest
    {
      VaultName = vault.VaultName
    };
    var responseNotifications = 
      client.GetVaultNotifications(requestNotifications);

    Console.WriteLine("  Notifications:");
    Console.WriteLine("    Topic: {0}", 
      responseNotifications.VaultNotificationConfig.SNSTopic);

    var events = responseNotifications.VaultNotificationConfig.Events;

    if (events.Any())
    {
      Console.WriteLine("    Events:");

      foreach (var e in events)
      {
        Console.WriteLine("{0}", e);
      }
    }
    else
    {
      Console.WriteLine("    No events set.");
    }
    
  }
  catch (ResourceNotFoundException)
  {
    Console.WriteLine("  No notifications set.");
  }
    
  var requestJobs = new ListJobsRequest{
    VaultName = vault.VaultName
  };
  var responseJobs = client.ListJobs(requestJobs);
  var jobs = responseJobs.JobList;
  
  if (jobs.Any())
  {
    Console.WriteLine("  Jobs:");

    foreach (var job in jobs)
    {
      Console.WriteLine("    For job ID: {0}", 
        job.JobId);
      Console.WriteLine("Archive ID: {0}", 
        job.ArchiveId);
      Console.WriteLine("Archive size in bytes: {0}", 
        job.ArchiveSizeInBytes.ToString());
      Console.WriteLine("Completed: {0}", 
        job.Completed);
      Console.WriteLine("Completion date: {0}", 
        job.CompletionDate);
      Console.WriteLine("Creation date: {0}", 
        job.CreationDate);
      Console.WriteLine("Inventory size in bytes: {0}", 
        job.InventorySizeInBytes);
      Console.WriteLine("Job description: {0}", 
        job.JobDescription);
      Console.WriteLine("Status code: {0}", 
        job.StatusCode.Value);
      Console.WriteLine("Status message: {0}", 
        job.StatusMessage);
    }

  }
  else
  {
    Console.WriteLine("  No jobs.");
  }

}

For additional examples, see:

For related API reference information, see Amazon.Glacier and Amazon.Glacier.Model in the AWS SDK for .NET API Reference.

High-Level APIs#

The the SDK provides high-level APIs for programming with Amazon Glacier. To further simplify application development, these high-level APIs offer a higher-level abstraction for some of the operations, including uploading an archive and downloading an archive or vault inventory.

For examples, see:

For related API reference information, see Amazon.Glacier.Transfer in the AWS SDK for .NET API Reference.

Resource APIs#

The the SDK provides the AWS Resource APIs for .NET for programming with Amazon Glacier. These resource APIs provide a resource-level programming model that enables you to write code to work more directly with Amazon Glacier resources as compared to their low-level and high-level API counterparts. (For more information about the AWS Resource APIs for .NET, including how to download and reference these resource APIs, see Programming with the AWS Resource APIs for .NET.)

The following example shows how to use the AWS Resource APIs for .NET to list accessible vaults in Amazon Glacier:

// using Amazon.Glacier.Resources;
// using Amazon.Runtime.Resources;

var g = new Glacier();

foreach (var vault in g.GetVaults())
{
  Console.WriteLine("Vault: {0}", vault.Name);
  Console.WriteLine("  Creation date: {0}", vault.CreationDate);
  Console.WriteLine("  Size in bytes: {0}", vault.SizeInBytes);
  Console.WriteLine("  Number of archives: {0}", vault.NumberOfArchives);

  try
  {
    var n = vault.GetNotification();

    Console.WriteLine("  Notifications:");
    Console.WriteLine("    Topic: {0}", n.SNSTopic);

    var events = n.Events;

    if (events.Any())
    {
      Console.WriteLine("    Events:");

      foreach (var e in events)
      {
        Console.WriteLine("{0}", e);
      }
    }
    else
    {
      Console.WriteLine("    No events set.");
    }

  }
  catch (ResourceLoadException)
  {
    Console.WriteLine("    No notifications set.");
  }

  var jobs = vault.GetJobs();

  if (jobs.Any())
  {
    Console.WriteLine("  Jobs:");

    foreach (var job in jobs)
    {
      Console.WriteLine("    For job ID: {0}",
        job.Id);
      Console.WriteLine("Archive ID: {0}",
        job.ArchiveId);
      Console.WriteLine("Archive size in bytes: {0}",
        job.ArchiveSizeInBytes.ToString());
      Console.WriteLine("Completed: {0}",
        job.Completed);
      Console.WriteLine("Completion date: {0}",
        job.CompletionDate);
      Console.WriteLine("Creation date: {0}",
        job.CreationDate);
      Console.WriteLine("Inventory size in bytes: {0}",
        job.InventorySizeInBytes);
      Console.WriteLine("Job description: {0}",
        job.JobDescription);
      Console.WriteLine("Status code: {0}",
        job.StatusCode.Value);
      Console.WriteLine("Status message: {0}",
        job.StatusMessage);
    }

  }
  else
  {
    Console.WriteLine("  No jobs.");
  }

}

For related API reference information, see Amazon.Glacier.Resources.

On this page: