使用 AWS SDK for Java 從 S3 Glacier 中的文件庫下載封存 - Amazon S3 Glacier

此頁面僅適用於使用 Vault 和 REST API 2012 年原始版本的 S3 Glacier 服務的現有客戶。

如果您要尋找封存儲存解決方案,建議您在 Amazon S3、S3 Glacier S3 Instant RetrievalS3 Glacier Flexible Retrieval 和 S3 Glacier Deep Archive 中使用 S3 Glacier 儲存類別。若要進一步了解這些儲存選項,請參閱 Amazon S3 使用者指南 中的使用 S3 Glacier 儲存類別的 S3 Glacier 儲存類別和長期資料儲存Amazon S3 這些儲存類別使用 Amazon S3 API,適用於所有區域,並且可以在 Amazon S3 主控台中管理。它們提供 Storage Cost Analysis、Storage Lens、進階選用加密功能等功能。

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

使用 AWS SDK for Java 從 S3 Glacier 中的文件庫下載封存

以下 Java 程式碼範例使用 AWS SDK for Java 的高階 API,下載您在之前步驟中上傳的封存。在程式碼範例中,請注意下列事項:

  • 範例會建立 AmazonGlacierClient 類別的執行個體。

  • 此程式碼使用美國西部 (奧勒岡) 區域 (us-west-2) 比對在 步驟 2:在 S3 Glacier 中建立保存庫 中建立文件庫的位置。

  • 此範例使用 AWS SDK for Java 高階 API 的 ArchiveTransferManager 類別的 download API 操作。此範例會建立 Amazon Simple Notification Service (Amazon SNS) 主題,以及訂閱該主題的 Amazon Simple Queue Service (Amazon SQS) 佇列。若您依照 步驟 1:開始 S3 Glacier 之前 的指示建立 AWS Identity and Access Management (IAM) 管理員使用者,使用者可擁有需要的 IAM 許可,以建立並使用 Amazon SNS 主題和 Amazon SQS 佇列。

如需執行此範例的逐步說明,請參閱 使用 Eclipse 執行 Amazon S3 Glacier 的 Java 範例。您需要按照在 步驟 3:將封存上傳至 S3 Glacier 中的保存庫 中上傳之檔案的封存 ID 來更新程式碼。

範例 :使用 AWS SDK for Java 下載封存
import java.io.File; import java.io.IOException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.services.glacier.AmazonGlacierClient; import com.amazonaws.services.glacier.transfer.ArchiveTransferManager; import com.amazonaws.services.sns.AmazonSNSClient; import com.amazonaws.services.sqs.AmazonSQSClient; public class AmazonGlacierDownloadArchive_GettingStarted { public static String vaultName = "examplevault"; public static String archiveId = "*** provide archive ID ***"; public static String downloadFilePath = "*** provide location to download archive ***"; public static AmazonGlacierClient glacierClient; public static AmazonSQSClient sqsClient; public static AmazonSNSClient snsClient; public static void main(String[] args) throws IOException { ProfileCredentialsProvider credentials = new ProfileCredentialsProvider(); glacierClient = new AmazonGlacierClient(credentials); sqsClient = new AmazonSQSClient(credentials); snsClient = new AmazonSNSClient(credentials); glacierClient.setEndpoint("glacier.us-west-2.amazonaws.com"); sqsClient.setEndpoint("sqs.us-west-2.amazonaws.com"); snsClient.setEndpoint("sns.us-west-2.amazonaws.com"); try { ArchiveTransferManager atm = new ArchiveTransferManager(glacierClient, sqsClient, snsClient); atm.download(vaultName, archiveId, new File(downloadFilePath)); } catch (Exception e) { System.err.println(e); } } }