SetVaultNotifications 搭配 AWS SDK 或 CLI 使用 - 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

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

SetVaultNotifications 搭配 AWS SDK 或 CLI 使用

下列程式碼範例示範如何使用 SetVaultNotifications

動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:

CLI
AWS CLI

下列命令可為名為 my-vault 的文件庫設定 SNS 通知:

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

notificationconfig.json 是目前資料夾中的 JSON 檔案,用來指定 SNS 主題和要發佈的事件:

{ "SNSTopic": "arn:aws:sns:us-west-2:0123456789012:my-vault", "Events": ["ArchiveRetrievalCompleted", "InventoryRetrievalCompleted"] }

Amazon Glacier 在執行操作時需要帳戶 ID 引數,但您可以使用連字號來指定使用中的帳戶。

Python
SDK for Python (Boto3)
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

class GlacierWrapper: """Encapsulates Amazon S3 Glacier API operations.""" def __init__(self, glacier_resource): """ :param glacier_resource: A Boto3 Amazon S3 Glacier resource. """ self.glacier_resource = glacier_resource def set_notifications(self, vault, sns_topic_arn): """ Sets an Amazon Simple Notification Service (Amazon SNS) topic as a target for notifications. Amazon S3 Glacier publishes messages to this topic for the configured list of events. :param vault: The vault to set up to publish notifications. :param sns_topic_arn: The Amazon Resource Name (ARN) of the topic that receives notifications. :return: Data about the new notification configuration. """ try: notification = self.glacier_resource.Notification("-", vault.name) notification.set( vaultNotificationConfig={ "SNSTopic": sns_topic_arn, "Events": [ "ArchiveRetrievalCompleted", "InventoryRetrievalCompleted", ], } ) logger.info( "Notifications will be sent to %s for events %s from %s.", notification.sns_topic, notification.events, notification.vault_name, ) except ClientError: logger.exception( "Couldn't set notifications to %s on %s.", sns_topic_arn, vault.name ) raise else: return notification
  • 如需 API 詳細資訊,請參閱《適用於 Python (Boto3) 的AWS 開發套件 API 參考》中的 SetVaultNotifications

如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱 搭配 AWS SDK 使用 Amazon Glacier 。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。