AWS SDKを使用して Amazon S3 Glacier ボールトインベントリを取得します - AWSSDK コードサンプル

AWSDoc AWS SDK サンプルリポジトリには、その他の SDK GitHub サンプルがあります

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDKを使用して Amazon S3 Glacier ボールトインベントリを取得します

次のコード例は、Amazon S3 Glacier ボールトインベントリを取得する方法を示しています。

アクション例は、より大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。次のコード例で、このアクションのコンテキストを確認できます。

Java
SDK for Java 2.x
注記

にはまだまだあります。 GitHub用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

public static String createJob(GlacierClient glacier, String vaultName, String accountId) { try { JobParameters job = JobParameters.builder() .type("inventory-retrieval") .build(); InitiateJobRequest initJob = InitiateJobRequest.builder() .jobParameters(job) .accountId(accountId) .vaultName(vaultName) .build(); InitiateJobResponse response = glacier.initiateJob(initJob); System.out.println("The job ID is: " +response.jobId()) ; System.out.println("The relative URI path of the job is: " +response.location()) ; return response.jobId(); } catch(GlacierException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; } // Poll S3 Glacier = Polling a Job may take 4-6 hours according to the Documentation. public static void checkJob(GlacierClient glacier, String jobId, String name, String account, String path) { try{ boolean finished = false; String jobStatus; int yy=0; while (!finished) { DescribeJobRequest jobRequest = DescribeJobRequest.builder() .jobId(jobId) .accountId(account) .vaultName(name) .build(); DescribeJobResponse response = glacier.describeJob(jobRequest); jobStatus = response.statusCodeAsString(); if (jobStatus.compareTo("Succeeded") == 0) finished = true; else { System.out.println(yy + " status is: " + jobStatus); Thread.sleep(1000); } yy++; } System.out.println("Job has Succeeded"); GetJobOutputRequest jobOutputRequest = GetJobOutputRequest.builder() .jobId(jobId) .vaultName(name) .accountId(account) .build(); ResponseBytes<GetJobOutputResponse> objectBytes = glacier.getJobOutputAsBytes(jobOutputRequest); // Write the data to a local file. byte[] data = objectBytes.asByteArray(); File myFile = new File(path); OutputStream os = new FileOutputStream(myFile); os.write(data); System.out.println("Successfully obtained bytes from a Glacier vault"); os.close(); } catch(GlacierException | InterruptedException | IOException e) { System.out.println(e.getMessage()); System.exit(1); } }
  • API の詳細については、AWS SDK for Java 2.xAPI InitiateJobリファレンスのを参照してください

Python
SDK for Python (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 initiate_inventory_retrieval(vault): """ Initiates an inventory retrieval job. The inventory describes the contents of the vault. Standard retrievals typically complete within 3—5 hours. When the job completes, you can get the inventory by calling get_output(). :param vault: The vault to inventory. :return: The inventory retrieval job. """ try: job = vault.initiate_inventory_retrieval() logger.info("Started %s job with ID %s.", job.action, job.id) except ClientError: logger.exception("Couldn't start job on vault %s.", vault.name) raise else: return job
  • API の詳細については、AWSSDK for Python (Boto3) API リファレンスのを参照してくださいInitiateJob