

 **此页面仅适用于使用文件库和 2012 年原始 REST API 的 Amazon Glacier 服务的现有客户。**

如果您正在寻找归档存储解决方案，建议使用 Amazon S3 中的 Amazon Glacier 存储类别 S3 Glacier Instant Retrieval、S3 Glacier Flexible Retrieval 和 S3 Glacier Deep Archive。要了解有关这些存储选项的更多信息，请参阅 [Amazon Glacier 存储类别](https://www.amazonaws.cn/s3/storage-classes/glacier/)。

Amazon Glacier（最初基于保管库的独立服务）不再接受新客户。Amazon Glacier 是一项独立的服务 APIs ，拥有自己的服务，可将数据存储在文件库中，不同于亚马逊 S3 和 Amazon S3 Glacier 存储类别。在 Amazon Glacier 中，您现有的数据将确保安全，并且可以无限期地访问。无需进行迁移。对于低成本、长期的存档存储， Amazon 建议[使用 Amazon S3 Glacier 存储类别，这些存储类别](https://www.amazonaws.cn/s3/storage-classes/glacier/)基于S3存储桶 APIs、完全 Amazon Web Services 区域 可用性、更低的成本和 Amazon 服务集成，可提供卓越的客户体验。如果您希望加强功能，可以考虑使用我们的 [Amazon 将数据从 Amazon Glacier 文件库传输到 Amazon S3 Glacier 存储类别的解决方案指南](https://www.amazonaws.cn/solutions/guidance/data-transfer-from-amazon-s3-glacier-vaults-to-amazon-s3/)，迁移到 Amazon S3 Glacier 存储类别。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在 Amazon Glacier 中使用配置文件库通知 适用于 .NET 的 Amazon SDK
使用 .NET 配置文件库通知

以下是使用 适用于 .NET 的 Amazon SDK低级 API 在文件库中配置通知的步骤。

 

1. 创建 `AmazonGlacierClient` 类（客户端）的实例。

   您需要指定文件库所在的 Amazon 区域。您使用此客户端执行的所有操作都适用于该 Amazon 区域。

1. 通过创建一个 `SetVaultNotificationsRequest` 类的实例提供通知配置信息。

   您需要提供文件库名称、通知配置信息和账户 ID。如果您不提供账户 ID，则系统会使用与您提供来对请求签名的证书相关联的账户 ID。有关更多信息，请参阅[将适用于 .NET 的 Amazon SDK 与 Amazon Glacier 结合使用](using-aws-sdk-for-dot-net.md)。

   在指定通知配置时，您可以提供一个现有的 Amazon SNS 主题的 Amazon 资源名称（ARN），以及您希望获得其通知的一个或多个事件。有关受支持的事件的列表，请参阅[设置文件库通知配置（PUT notification-configuration）](api-vault-notifications-put.md)。

1. 以参数形式提供请求对象，运行 `SetVaultNotifications` 方法。

1. 在文件库中设置通知配置后，您可以通过调用 `GetVaultNotifications` 方法检索配置信息，也可以通过调用客户端提供的 `DeleteVaultNotifications` 方法删除它。

## 示例：使用在文件库上设置通知配置 适用于 .NET 的 Amazon SDK


以下 C\$1 代码示例说明了前面的步骤。该示例在美国西部（俄勒冈州）区域的文件库（“`examplevault`”）中设置了通知配置并检索了配置，然后删除了配置。当 `ArchiveRetrievalCompleted` 事件或 `InventoryRetrievalCompleted` 事件发生时，该配置会请求 Amazon Glacier（Amazon Glacier）向指定的 Amazon SNS 主题发送通知。

**注意**  
有关底层 REST API 的信息，请参阅[文件库操作](vault-operations.md)。

有关运行以下示例的 step-by-step说明，请参阅[运行代码示例](using-aws-sdk-for-dot-net.md#setting-up-and-testing-sdk-dotnet)。您需要更新该代码并提供现有的文件库名称和 Amazon SNS 主题。

**Example**  

```
using System;
using System.Collections.Generic;
using Amazon.Glacier;
using Amazon.Glacier.Model;
using Amazon.Runtime;

namespace glacier.amazon.com.docsamples
{
  class VaultNotificationSetGetDelete
  {
    static string vaultName   = "examplevault";
    static string snsTopicARN = "*** Provide Amazon SNS topic ARN ***";

    static IAmazonGlacier client;

    public static void Main(string[] args)
    {
      try
      {
        using (client = new AmazonGlacierClient(Amazon.RegionEndpoint.USWest2))
        {
          Console.WriteLine("Adding notification configuration to the vault.");
          SetVaultNotificationConfig();
          GetVaultNotificationConfig();
          Console.WriteLine("To delete vault notification configuration, press Enter");
          Console.ReadKey();
          DeleteVaultNotificationConfig();
        }
      }
      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 void SetVaultNotificationConfig()
    {

      SetVaultNotificationsRequest request = new SetVaultNotificationsRequest()
      {     
        VaultName = vaultName,
        VaultNotificationConfig = new VaultNotificationConfig()
        {
          Events   = new List<string>() { "ArchiveRetrievalCompleted", "InventoryRetrievalCompleted" },
          SNSTopic = snsTopicARN
        }
      };
      SetVaultNotificationsResponse response = client.SetVaultNotifications(request);
    }

    static void GetVaultNotificationConfig()
    {
      GetVaultNotificationsRequest request = new GetVaultNotificationsRequest()
      {
        VaultName = vaultName,
        AccountId = "-"
      };
      GetVaultNotificationsResponse response = client.GetVaultNotifications(request);
      Console.WriteLine("SNS Topic ARN: {0}", response.VaultNotificationConfig.SNSTopic);
      foreach (string s in response.VaultNotificationConfig.Events)
        Console.WriteLine("Event : {0}", s);
    }

    static void DeleteVaultNotificationConfig()
    {
      DeleteVaultNotificationsRequest request = new DeleteVaultNotificationsRequest()
      {  
        VaultName = vaultName
      };
      DeleteVaultNotificationsResponse response = client.DeleteVaultNotifications(request);
    }
  }
}
```