

 **此頁面僅適用於使用 Vaults 和 2012 年原始 REST API 的 Amazon Glacier 服務的現有客戶。**

如果您要尋找封存儲存解決方案，建議您在 Amazon Glacier Instant Retrieval、S3 Glacier Flexible Retrieval 和 S3 Glacier Deep Archive 中使用 Amazon Glacier 儲存類別。 Amazon S3 若要進一步了解這些儲存選項，請參閱 [Amazon Glacier 儲存類別](https://aws.amazon.com/s3/storage-classes/glacier/)。

Amazon Glacier （原始獨立保存庫型服務） 不再接受新客戶。Amazon Glacier 是一項獨立服務，具有自己的 APIs，可將資料存放在保存庫中，並與 Amazon S3 和 Amazon S3 Glacier 儲存類別不同。您現有的資料將在 Amazon Glacier 中無限期保持安全且可存取。不需要遷移。對於低成本、長期的封存儲存， AWS 建議使用 [Amazon S3 Glacier 儲存類別](https://aws.amazon.com/s3/storage-classes/glacier/)，透過 S3 儲存貯體型 APIs、完整 AWS 區域 可用性、降低成本 AWS 和服務整合，提供卓越的客戶體驗。如果您想要增強功能，請考慮使用我們的解決方案指南，將資料從 Amazon S3 Glacier 保存庫傳輸至 Amazon S3 Glacier 儲存類別，以遷移至 Amazon S3 Glacier 儲存類別。 [AWS Amazon Glacier Amazon S3 ](https://aws.amazon.com/solutions/guidance/data-transfer-from-amazon-s3-glacier-vaults-to-amazon-s3/)

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 Amazon Glacier 中設定保存庫通知
<a name="configuring-notifications"></a>

從 Amazon Glacier 擷取任何內容，例如從保存庫或保存庫庫存封存，都是兩個步驟。

1. 啟動擷取任務。

1. 工作完成後，下載工作輸出。

可以在保存庫中設定通知設定，以便在工作完成後，將訊息傳送到 Amazon Simple Notification Service (Amazon SNS) 主題。

**Topics**
+ [在 Amazon Glacier 中設定保存庫通知：一般概念](#configuring-notifications.general)
+ [使用 在 Amazon Glacier 中設定保存庫通知 適用於 Java 的 AWS SDK](configuring-notifications-sdk-java.md)
+ [使用 在 Amazon Glacier 中設定保存庫通知 適用於 .NET 的 AWS SDK](configuring-notifications-sdk-dotnet.md)
+ [使用 REST API 在 Amazon Glacier 中設定保存庫通知](configuring-notifications-rest-api.md)
+ [使用 Amazon Glacier 主控台設定保存庫通知](configuring-notifications-console.md)
+ [使用 設定保存庫通知 AWS Command Line Interface](configuring-notifications-cli.md)

## 在 Amazon Glacier 中設定保存庫通知：一般概念
<a name="configuring-notifications.general"></a>

Amazon Glacier 擷取任務請求會以非同步方式執行。您必須等到 Amazon Glacier 完成任務，才能取得其輸出。您可以定期輪詢 Amazon Glacier 以判斷任務狀態，但這不是最佳方法。Amazon Glacier 也支援通知。工作完成後，該工作就可將訊息張貼到 Amazon Simple Notification Service (Amazon SNS) 主題。使用此功能需要您在保存庫上設定通知設定。在組態中，您可以識別一或多個事件，以及您希望 Amazon Glacier 在事件發生時傳送訊息的 Amazon SNS 主題。 Amazon Glacier 

Amazon Glacier 會定義與任務完成 (`ArchiveRetrievalCompleted`、`InventoryRetrievalCompleted`) 特別相關的事件，您可以將這些事件新增至保存庫的通知組態。特定任務完成後，Amazon Glacier 會將通知訊息發佈至 SNS 主題。

 通知組態是 JSON 文件，如以下範例所示。

```
{    
   "SNSTopic": "arn:aws:sns:us-west-2:012345678901:mytopic",    
   "Events": ["ArchiveRetrievalCompleted", "InventoryRetrievalCompleted"] 
}
```

請注意，您只能為保存庫設定一個 Amazon SNS 主題。

 

**注意**  
將通知組態新增至保存庫會導致 Amazon Glacier 每次發生通知組態中指定的事件時傳送通知。您還可以選擇在每個工作啟動請求中指定 Amazon SNS 主題。如果您在保存庫上新增通知組態，並在啟動任務請求中指定 Amazon SNS 主題，Amazon Glacier 會傳送這兩個通知。

Amazon Glacier 傳送的任務完成訊息包含諸如任務類型 (`InventoryRetrieval`、`ArchiveRetrieval`)、任務完成狀態、SNS 主題名稱、任務狀態碼和保存庫 ARN 等資訊。以下是 Amazon Glacier 在完成`InventoryRetrieval`任務後傳送至 SNS 主題的範例通知。

```
{
 "Action": "InventoryRetrieval",
 "ArchiveId": null,
 "ArchiveSizeInBytes": null,
 "Completed": true,
 "CompletionDate": "2012-06-12T22:20:40.790Z",
 "CreationDate": "2012-06-12T22:20:36.814Z",
 "InventorySizeInBytes":11693,
 "JobDescription": "my retrieval job",
 "JobId":"HkF9p6o7yjhFx-K3CGl6fuSm6VzW9T7esGQfco8nUXVYwS0jlb5gq1JZ55yHgt5vP54ZShjoQzQVVh7vEXAMPLEjobID",
 "SHA256TreeHash":null,
 "SNSTopic": "arn:aws:sns:us-west-2:012345678901:mytopic",
 "StatusCode":"Succeeded",
 "StatusMessage": "Succeeded",
 "VaultARN": "arn:aws:glacier:us-west-2:012345678901:vaults/examplevault"
}
```

如果 `Completed` 欄位為 true，您還必須檢查 `StatusCode` 來確認任務順利完成還是失敗。

**注意**  
請注意，Amazon SNS 主題必須允許保存庫發布通知。在預設情況下，只有 Amazon SNS 主題擁有者可以向該主題發布訊息。不過，如果 Amazon SNS 主題和保存庫是由不同的 擁有 AWS 帳戶，則您必須設定 Amazon SNS 主題以接受保存庫中的發佈。您可以在 Amazon SNS 主控台設定 Amazon SNS 主題政策。

如需 Amazon SNS 的詳細資訊，請參閱 [Amazon SNS 入門](https://docs.aws.amazon.com/sns/latest/gsg/Welcome.html)。

# 使用 在 Amazon Glacier 中設定保存庫通知 適用於 Java 的 AWS SDK
<a name="configuring-notifications-sdk-java"></a>

以下是使用 適用於 Java 的 AWS SDK低階 API 設定保存庫通知的步驟。

 

1. 建立 `AmazonGlacierClient` 類別的執行個體 (用戶端)。

   您需要指定保存庫所在的 AWS 區域。您使用此用戶端執行的所有操作都會套用到該 AWS 區域。

1. 您可以透過建立 `SetVaultNotificationsRequest` 類別的執行個體，來提供通知組態資訊。

   您需要提供保存庫名稱、通知組態資訊和帳戶 ID。在指定通知設定時，您提供現有 Amazon SNS 主題的 Amazon Resource Name (ARN) 和要進行通知的一或多個事件。如需支援的事件清單，請參閱[設定保存庫通知組態 (PUT 通知的組態)](api-vault-notifications-put.md))。

1. 以參數形式提供請求物件，以便執行 `setVaultNotifications` 方法。

下列 Java 程式碼片段描述前述步驟。程式碼片段在文件庫上設定通知組態。當`ArchiveRetrievalCompleted`事件發生或`InventoryRetrievalCompleted`事件發生時，組態會要求 Amazon Glacier (Amazon Glacier) 傳送通知至指定的 Amazon SNS 主題。

 

```
SetVaultNotificationsRequest request = new SetVaultNotificationsRequest()
        .withAccountId("-")
        .withVaultName("*** provide vault name ***")
        .withVaultNotificationConfig(
                new VaultNotificationConfig()
                .withSNSTopic("*** provide SNS topic ARN ***")
                .withEvents("ArchiveRetrievalCompleted", "InventoryRetrievalCompleted")
         );
client.setVaultNotifications(request);
```

 

**注意**  
如需基礎 REST API 的資訊，請參閱 [保存庫作業](vault-operations.md)。

## 範例：使用 在保存庫上設定通知組態 適用於 Java 的 AWS SDK
<a name="configuring-notifications-sdk-java-example"></a>

以下 Java 程式碼範例設定文件庫的通知組態，刪除組態，然後復原組態。如需如何執行下列範例的逐步說明，請參閱 [適用於 Java 的 AWS SDK 搭配 Amazon Glacier 使用](using-aws-sdk-for-java.md)。

**Example**  

```
import java.io.IOException;

import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.glacier.AmazonGlacierClient;
import com.amazonaws.services.glacier.model.DeleteVaultNotificationsRequest;
import com.amazonaws.services.glacier.model.GetVaultNotificationsRequest;
import com.amazonaws.services.glacier.model.GetVaultNotificationsResult;
import com.amazonaws.services.glacier.model.SetVaultNotificationsRequest;
import com.amazonaws.services.glacier.model.VaultNotificationConfig;


public class AmazonGlacierVaultNotifications {

    public static AmazonGlacierClient client;
    public static String vaultName = "*** provide vault name ****";
    public static String snsTopicARN = "*** provide sns topic ARN ***";

    public static void main(String[] args) throws IOException {

    	ProfileCredentialsProvider credentials = new ProfileCredentialsProvider();

        client = new AmazonGlacierClient(credentials);        
        client.setEndpoint("https://glacier.us-east-1.amazonaws.com/");

        try {

            System.out.println("Adding notification configuration to the vault.");
            setVaultNotifications();
            getVaultNotifications();
            deleteVaultNotifications();
            
        } catch (Exception e) {
            System.err.println("Vault operations failed." + e.getMessage());
        }
    }

    private static void setVaultNotifications() {
        VaultNotificationConfig config = new VaultNotificationConfig()
            .withSNSTopic(snsTopicARN)
            .withEvents("ArchiveRetrievalCompleted", "InventoryRetrievalCompleted");
        
        SetVaultNotificationsRequest request = new SetVaultNotificationsRequest()
                .withVaultName(vaultName)
                .withVaultNotificationConfig(config);
                                
        client.setVaultNotifications(request);
        System.out.println("Notification configured for vault: " + vaultName);
    }

    private static void getVaultNotifications() {
        VaultNotificationConfig notificationConfig = null;
        GetVaultNotificationsRequest request = new GetVaultNotificationsRequest()
                .withVaultName(vaultName);
        GetVaultNotificationsResult result = client.getVaultNotifications(request);
        notificationConfig = result.getVaultNotificationConfig();

        System.out.println("Notifications configuration for vault: "
                + vaultName);
        System.out.println("Topic: " + notificationConfig.getSNSTopic());
        System.out.println("Events: " + notificationConfig.getEvents());
    }

    private static void deleteVaultNotifications() {
            DeleteVaultNotificationsRequest request = new DeleteVaultNotificationsRequest()
                .withVaultName(vaultName);
            client.deleteVaultNotifications(request);
            System.out.println("Notifications configuration deleted for vault: " + vaultName);
    }
}
```

# 使用 在 Amazon Glacier 中設定保存庫通知 適用於 .NET 的 AWS SDK
<a name="configuring-notifications-sdk-dotnet"></a>

以下是使用 適用於 .NET 的 AWS SDK低階 API 設定保存庫通知的步驟。

 

1. 建立 `AmazonGlacierClient` 類別的執行個體 (用戶端)。

   您需要指定保存庫所在的 AWS 區域。您使用此用戶端執行的所有操作都會套用到該 AWS 區域。

1. 您可以透過建立 `SetVaultNotificationsRequest` 類別的執行個體，來提供通知組態資訊。

   您需要提供保存庫名稱、通知組態資訊和帳戶 ID。如果您不提供帳戶 ID，則會使用與您提供來簽署請求之登入資料關聯的帳戶 ID。如需詳細資訊，請參閱[適用於 .NET 的 AWS SDK 搭配 Amazon Glacier 使用](using-aws-sdk-for-dot-net.md)。

   在指定通知設定時，您提供現有 Amazon SNS 主題的 Amazon Resource Name (ARN) 和要進行通知的一或多個事件。如需支援的事件清單，請參閱[設定保存庫通知組態 (PUT 通知的組態)](api-vault-notifications-put.md))。

1. 以參數形式提供請求物件，以便執行 `SetVaultNotifications` 方法。

1. 在設定有關保存庫的通知組態之後，您可以透過呼叫 `GetVaultNotifications` 方法擷取組態資訊，以及透過呼叫用戶端所提供的 `DeleteVaultNotifications` 方法將其移除。

## 範例：使用 在保存庫上設定通知組態 適用於 .NET 的 AWS SDK
<a name="creating-vaults-sdk-dotnet-example-notification"></a>

下列 C\$1 程式碼範例描述前述步驟。此範例在美國西部 (奧勒岡) 區域設定有關保存庫 (「`examplevault`」) 的通知設定、擷取設定，然後將其刪除。當`ArchiveRetrievalCompleted`事件發生或`InventoryRetrievalCompleted`事件發生時，組態會要求 Amazon Glacier (Amazon Glacier) 傳送通知至指定的 Amazon SNS 主題。

**注意**  
如需基礎 REST API 的資訊，請參閱 [保存庫作業](vault-operations.md)。

如需執行下列範例的逐步說明，請參閱「[執行程式碼範例](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.rproxy.govskope.ca.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);
    }
  }
}
```

# 使用 REST API 在 Amazon Glacier 中設定保存庫通知
<a name="configuring-notifications-rest-api"></a>

若要使用 REST API 設定文件庫通知，請參閱 [設定保存庫通知組態 (PUT 通知的組態)](api-vault-notifications-put.md)。此外，您還可以取得文件庫通知 ([取得文件庫通知 (GET 通知的組態)](api-vault-notifications-get.md)) 和刪除文件庫通知 ([刪除保存庫通知 (DELETE 通知的組態)](api-vault-notifications-delete.md))。

# 使用 Amazon Glacier 主控台設定保存庫通知
<a name="configuring-notifications-console"></a>

本節說明如何使用 Amazon Glacier 主控台設定保存庫通知。設定通知時，您可以指定工作完成事件，其會將通知傳送至 Amazon Simple Notification Service (Amazon SNS) 主題。除了設定保存庫通知外，您也可以指定在啟動工作時發布通知的主題。如果將保存件庫設為通知特定事件，並且在工作啟動請求中設定通知，則會傳送兩個通知。

**要設定文件庫通知**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/glacier/home](https://console.aws.amazon.com/glacier/home)：// 開啟 Amazon Glacier 主控台。

1. 在左側導覽窗格中，選擇**保存庫**。

1. 在**保存庫**清單中，選擇保存庫。

1. 在**通知**區段中，選擇**編輯**。

1. 在**事件通知**頁面，選擇**開啟通知**。

1. 在**通知**區段中，選擇下列其中一個 Amazon Simple Notification Service (Amazon SNS) 選項，然後按照對應的步驟進行作業：    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/amazonglacier/latest/dev/configuring-notifications-console.html)

1. 在**事件**下，選取您要傳送通知的一或兩個事件：
   + 若要僅在封存擷取工作完成時傳送通知，請選取**封存擷取工作完成**。
   + 若要僅在保存庫庫存工作完成時傳送通知，請選取**保存庫庫存擷取工作完成**。

# 使用 設定保存庫通知 AWS Command Line Interface
<a name="configuring-notifications-cli"></a>

本節說明如何使用 AWS Command Line Interface設定保存庫通知。設定通知時，您要指定工作完成事件，其會觸發對 Amazon Simple Notification Service (Amazon SNS) 主題的通知。除了設定文件庫通知外，您也可以指定在啟動作業時發佈通知的主題。如果您的文件庫設定為通知特定事件，並且在作業啟動請求中指定通知，則會發送兩個通知。

請遵循下列步驟，使用 AWS CLI設定保存庫通知。

**Topics**
+ [（先決條件） 設定 AWS CLI](#Creating-Vaults-CLI-Setup)
+ [範例：使用 設定保存庫通知 AWS CLI](#Configure-Vault-Notifications-CLI-Implementation)

## （先決條件） 設定 AWS CLI
<a name="Creating-Vaults-CLI-Setup"></a>

1. 下載和設定 AWS CLI。如需相關指示，請參閱《AWS Command Line Interface 使用者指南》**中的下列主題：

    [安裝 AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/userguide/installing.html) 

   [設定 AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html)

1. 在命令提示中輸入下列命令來驗證您的 AWS CLI 設定。這些命令不會明確提供登入資料，因此會使用預設描述檔的登入資料。
   + 嘗試使用幫助命令。

     ```
     aws help
     ```
   + 若要取得已設定帳戶上的 Amazon Glacier 保存庫清單，請使用 `list-vaults`命令。將 *123456789012* 取代為您的 AWS 帳戶 ID。

     ```
     aws glacier list-vaults --account-id 123456789012
     ```
   + 若要查看 目前的組態資料 AWS CLI，請使用 `aws configure list`命令。

     ```
     aws configure list
     ```

## 範例：使用 設定保存庫通知 AWS CLI
<a name="Configure-Vault-Notifications-CLI-Implementation"></a>

1. 使用 `set-vault-notifications` 命令，設定保存庫發生特定事件時將傳送的通知。根據預設，您不會收到任何通知。

   ```
   aws glacier set-vault-notifications --vault-name examplevault --account-id 111122223333 --vault-notification-config file://notificationconfig.json
   ```

1.  通知組態是 JSON 文件，如以下範例所示。

   ```
   {    
      "SNSTopic": "arn:aws:sns:us-west-2:012345678901:mytopic",    
      "Events": ["ArchiveRetrievalCompleted", "InventoryRetrievalCompleted"] 
   }
   ```

   如需針對 Amazon Glacier 使用 Amazon SNS 主題的詳細資訊，請參閱在 [Amazon Glacier 中設定保存庫通知：一般概念](configuring-notifications.html#configuring-notifications.general) Amazon Glacier 

   如需 Amazon SNS 的詳細資訊，請參閱 [Amazon SNS 入門](https://docs.aws.amazon.com/sns/latest/gsg/Welcome.html)。