Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Get Amazon S3 Glacier job output using an Amazon SDK
The following code example shows how to get Amazon S3 Glacier job output.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in
context in the following code example:
- Python
-
- SDK for Python (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
For a complete list of Amazon SDK developer guides and code examples, see
Using S3 Glacier with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.