将 GetVaultNotifications 与 AWS SDK 或 CLI 配合使用 - AWS SDK 代码示例

AWS 文档 SDK 示例 GitHub 存储库中还有更多 AWS SDK 示例。

GetVaultNotifications 与 AWS SDK 或 CLI 配合使用

以下代码示例演示如何使用 GetVaultNotifications

CLI
AWS CLI

以下命令获取名为 my-vault 的文件库的通知配置的描述:

aws glacier get-vault-notifications --account-id - --vault-name my-vault

输出:

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

如果没有为该文件库配置任何通知,则会返回错误。Amazon Glacier 在执行操作时需要一个账户 ID 参数,但您可以使用连字符来指定正在使用的账户。

Python
适用于 Python 的 SDK (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 @staticmethod def get_notification(vault): """ Gets the currently notification configuration for a vault. :param vault: The vault to query. :return: The notification configuration for the specified vault. """ try: notification = vault.Notification() logger.info( "Vault %s notifies %s on %s events.", vault.name, notification.sns_topic, notification.events, ) except ClientError: logger.exception("Couldn't get notification data for %s.", vault.name) raise else: return notification
  • 有关 API 详细信息,请参阅《AWS SDK for Python(Boto3)API Reference》中的 GetVaultNotifications