此页面仅适用于使用文件库和 2012 年原始 REST API 的 Amazon Glacier 服务的现有客户。
如果您正在寻找归档存储解决方案,建议使用 Amazon S3 中的 Amazon Glacier 存储类别 S3 Glacier Instant Retrieval、S3 Glacier Flexible Retrieval 和 S3 Glacier Deep Archive。要了解有关这些存储选项的更多信息,请参阅 Amazon Glacier 存储类别。
从 2025 年 12 月 15 日起,Amazon Glacier(最初基于独立文件库的服务)将不再接受新客户,对现有客户不存在任何影响。Amazon Glacier 是一项独立服务,拥有自己的 API,可将数据存储在文件库中,与 Amazon S3 和 Amazon S3 Glacier 存储类别不同。在 Amazon Glacier 中,您现有的数据将确保安全,并且可以无限期地访问。无需进行迁移。对于低成本、长期的存档存储,AWS 建议使用 Amazon S3 Glacier 存储类别,该类别可通过基于 S3 存储桶的 API、完全的 AWS 区域可用性、更低的成本和 AWS 服务集成,提供卓越的客户体验。如果您希望加强功能,可以考虑使用我们的 AWS 将数据从 Amazon Glacier 文件库传输到 Amazon S3 Glacier 存储类别的解决方案指南,迁移到 Amazon S3 Glacier 存储类别。
将 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
-
- 适用于 Python 的 SDK(Boto3)
-
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
有关 AWS SDK 开发人员指南和代码示例的完整列表,请参阅将 Amazon Glacier 与 AWS SDK 结合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。