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).
List Amazon S3 Glacier jobs using an Amazon SDK
The following code examples show how to list Amazon S3 Glacier jobs.
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 examples:
- .NET
-
- Amazon SDK for .NET
-
/// <summary>
/// List Amazon S3 Glacier jobs.
/// </summary>
/// <param name="vaultName">The name of the vault to list jobs for.</param>
/// <returns>A list of Amazon S3 Glacier jobs.</returns>
public async Task<List<GlacierJobDescription>> ListJobsAsync(string vaultName)
{
var request = new ListJobsRequest
{
// Using a hyphen "-" for the Account Id will
// cause the SDK to use the Account Id associated
// with the current account.
AccountId = "-",
VaultName = vaultName,
};
var response = await _glacierService.ListJobsAsync(request);
return response.JobList;
}
- 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 list_jobs(vault, job_type):
"""
Lists jobs by type for the specified vault.
:param vault: The vault to query.
:param job_type: The type of job to list.
:return: The list of jobs of the requested type.
"""
job_list = []
try:
if job_type == "all":
jobs = vault.jobs.all()
elif job_type == "in_progress":
jobs = vault.jobs_in_progress.all()
elif job_type == "completed":
jobs = vault.completed_jobs.all()
elif job_type == "succeeded":
jobs = vault.succeeded_jobs.all()
elif job_type == "failed":
jobs = vault.failed_jobs.all()
else:
jobs = []
logger.warning("%s isn't a type of job I can get.", job_type)
for job in jobs:
job_list.append(job)
logger.info("Got %s %s job %s.", job_type, job.action, job.id)
except ClientError:
logger.exception("Couldn't get %s jobs from %s.", job_type, vault.name)
raise
else:
return job_list
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.