在 Amazon S3 Glacier 中使用 适用于 Java 的 Amazon SDK中配置文件库通知 - Amazon S3 Glacier
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

此页面仅适用于使用文件库和 2012 年原始 REST API 的 S3 Glacier 服务的现有客户。

如果您正在寻找归档存储解决方案,建议使用 Amazon S3 中的 S3 Glacier 存储类 S3 Glacier Instant RetrievalS3 Glacier Flexible RetrievalS3 Glacier Deep Archive。要了解有关这些存储选项的更多信息,请参阅《Amazon S3 用户指南》中的 S3 Glacier 存储类使用 S3 Glacier 存储类的长期数据存储。这些存储类使用 Amazon S3 API,适用于所有区域,并且可以在 Amazon S3 控制台中管理。它们提供存储成本分析、Storage Lens 存储分析功能、高级可选加密功能等功能。

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

在 Amazon S3 Glacier 中使用 适用于 Java 的 Amazon SDK中配置文件库通知

以下是使用 适用于 Java 的 Amazon SDK低级 API 在文件库中配置通知的步骤。

  1. 创建 AmazonGlacierClient 类(客户端)的实例。

    您需要指定文件库所在的 Amazon 区域。您使用此客户端执行的所有操作都适用于该 Amazon 区域。

  2. 通过创建一个 SetVaultNotificationsRequest 类的实例提供通知配置信息。

    您需要提供文件库名称、通知配置信息和账户 ID。在指定通知配置时,您可以提供一个现有的 Amazon SNS 主题的 Amazon 资源名称(ARN),以及您希望获得其通知的一个或多个事件。有关受支持的事件的列表,请参阅“设置文件库通知配置(设置通知配置)”。

  3. 以参数形式提供请求对象,运行 setVaultNotifications 方法。

以下 Java 代码段说明了前面的步骤。该代码段在文件库中设置了通知配置。当 ArchiveRetrievalCompleted 事件或 InventoryRetrievalCompleted 事件发生时,该配置会请求 Amazon S3 Glacier(S3 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 的 Amazon SDK

以下 Java 代码示例设置了文件库的通知配置并删除了配置,然后恢复了配置。有关如何运行以下示例的 step-by-step说明,请参阅适用于 Java 的 Amazon SDK 与 Amazon S3 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); } }