Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
此页面仅适用于使用文件库和 2012 年原始 REST API 的 S3 Glacier 服务的现有客户。
如果您正在寻找归档存储解决方案,建议使用 Amazon S3 中的 S3 Glacier 存储类 S3 Glacier Instant Retrieval、S3 Glacier Flexible Retrieval 和 S3 Glacier Deep Archive。要了解有关这些存储选项的更多信息,请参阅《Amazon S3 用户指南》中的 S3 Glacier 存储类和使用 S3 Glacier 存储类的长期数据存储。这些存储类使用 Amazon S3 API,适用于所有区域,并且可以在 Amazon S3 控制台中管理。它们提供存储成本分析、Storage Lens 存储分析功能、高级可选加密功能等功能。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
GetJobOutput
与 Amazon SDK 或 CLI 配合使用
以下代码示例演示如何使用 GetJobOutput
。
操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:
- CLI
-
- Amazon CLI
-
以下命令将文件库清单任务的输出保存到名为 output.json
的当前目录中的某个文件中:
aws glacier get-
job-output --account-id - --vault-name my-vault
--job-id zbxcm3Z_3z5UkoroF7SuZKrxgGoDc3RloGduS7Eg-RO47Yc6FxsdGBgf_Q2DK5Ejh18CnTS5XW4_XqlNHS61dsO4CnMW
output.json
可在 aws glacier list-jobs
输出中找到 job-id
。请注意,输出文件名是一个位置参数,不以选项名称作为前缀。Amazon Glacier 在执行操作时需要一个账户 ID 参数,但您可以使用连字符来指定正在使用的账户。
输出:
{
"status": 200,
"acceptRanges": "bytes",
"contentType": "application/json"
}
output.json
:
{"VaultARN":"arn:aws:glacier:us-west-2:0123456789012:vaults/my-vault","InventoryDate":"2015-04-07T00:26:18Z","ArchiveList":[{"ArchiveId":"kKB7ymWJVpPSwhGP6ycSOAekp9ZYe_--zM_mw6k76ZFGEIWQX-ybtRDvc2VkPSDtfKmQrj0IRQLSGsNuDp-AJVlu2ccmDSyDUmZwKbwbpAdGATGDiB3hHO0bjbGehXTcApVud_wyDw","ArchiveDescription":"multipart upload test","CreationDate":"2015-04-06T22:24:34Z","Size":3145728,"SHA256TreeHash":"9628195fcdbcbbe76cdde932d4646fa7de5f219fb39823836d81f0cc0e18aa67"}]}
- PowerShell
-
- 用于 PowerShell
-
示例 1:下载计划在指定任务中检索的档案内容,并将这些内容存储到磁盘上的文件中。如果有校验和,则下载会为您验证校验和。如果需要,可以通过指定 -Select '*'
来返回包括校验和在内的整个响应。
Read-GLCJobOutput -VaultName myvault -JobId "HSWjArc...Zq2XLiW" -FilePath "c:\temp\blue.bin"
- Python
-
- 适用于 Python 的 SDK(Boto3)
-
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_job_output(job):
"""
Gets the output of a job, such as a vault inventory or the contents of an
archive.
:param job: The job to get output from.
:return: The job output, in bytes.
"""
try:
response = job.get_output()
out_bytes = response["body"].read()
logger.info("Read %s bytes from job %s.", len(out_bytes), job.id)
if "archiveDescription" in response:
logger.info(
"These bytes are described as '%s'", response["archiveDescription"]
)
except ClientError:
logger.exception("Couldn't get output for job %s.", job.id)
raise
else:
return out_bytes
有关 S Amazon DK 开发者指南和代码示例的完整列表,请参阅将 S3 Glacier 与 Amazon SDK 结合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。