使用 在 Amazon Glacier 中設定保存庫通知 適用於 Java 的 AWS SDK - Amazon Glacier

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

如果您要尋找封存儲存解決方案,建議您在 Amazon Glacier Instant Retrieval、S3 Glacier Flexible Retrieval 和 S3 Glacier Deep Archive 中使用 Amazon Glacier 儲存類別。 Amazon S3 若要進一步了解這些儲存選項,請參閱 Amazon Glacier 儲存類別

自 2025 年 12 月 15 日起,Amazon Glacier (原始獨立保存庫型服務) 將不再接受新客戶,不會影響現有客戶。Amazon Glacier 是一項獨立服務,具有自己的 APIs,可將資料存放在保存庫中,並與 Amazon S3 和 Amazon S3 Glacier 儲存類別不同。您現有的資料將在 Amazon Glacier 中無限期保持安全且可存取。不需要遷移。對於低成本、長期的封存儲存, AWS 建議採用 Amazon S3 Glacier 儲存類別,透過 S3 儲存貯體型 APIs、完整 AWS 區域 可用性、降低成本 AWS 和服務整合,提供卓越的客戶體驗。如果您想要增強功能,請考慮使用我們的解決方案指南,將資料從 Amazon S3 Glacier 保存庫傳輸至 Amazon S3 Glacier 儲存類別,以遷移至 Amazon S3 Glacier 儲存類別。 AWS Amazon Glacier Amazon S3

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

使用 在 Amazon Glacier 中設定保存庫通知 適用於 Java 的 AWS SDK

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

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

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

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

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

  3. 以參數形式提供請求物件,以便執行 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 的資訊,請參閱 保存庫作業

範例:使用 在保存庫上設定通知組態 適用於 Java 的 AWS SDK

以下 Java 程式碼範例設定文件庫的通知組態,刪除組態,然後復原組態。如需如何執行下列範例的逐步說明,請參閱 適用於 Java 的 AWS SDK 搭配 Amazon Glacier 使用

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); } }