Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 SAmazon DK 设置 Amazon S3 Glacier 文件库通知
以下代码示例显示如何设置 Amazon S3 Glacier 文件库通知。
- Python
-
- 适用于 Python (Boto3) 的 SDK
-
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
有关 Amazon 软件开发工具包开发人员指南和代码示例的完整列表,请参阅 将 S3 Glacier 与结合使用Amazon开发工具包。本主题还包括有关入门的信息以及有关先前的软件开发工具包版本的详细信息。