Amazon Glacier: List Jobs with Pagination and Status Filters
See more Amazon Glacier Examples
For existing Amazon Glacier vault customers. The standalone vault service is closed to new customers. These examples use its REST API version 2012-06-01, not the S3 bucket APIs used by S3 Glacier storage classes. See AWS service guidance.
Lists active and recently completed jobs for one vault, with optional statuscode and completed filters. Leave both configuration strings empty to list all statuses. Allowed status values are InProgress, Succeeded, and Failed; completion values are lowercase true and false. Empty means omitted: completed=false explicitly selects unfinished jobs. When both filters are set, both must match; contradictory choices can return an empty result.
Uses limit=50, follows the top-level response Marker even after an empty page, and retains the filters on every request. Raw markers are encoded by AddQueryParam. A repeated, missing, or malformed marker or the 1,000-page bound stops with incomplete results. InventoryRetrievalParameters.Marker inside a job belongs to inventory retrieval and must not be used for job-list pagination.
Prints job IDs, action, status, completion, and available dates, sizes, and tier. Nullable fields are checked before use; sizes stay decimal strings to preserve large integers. A failed job does not stop enumeration. Completed does not necessarily mean succeeded. Use DescribeJob to check a selected job, then download archive output or download CSV inventory output.
Requires glacier:ListJobs on the target vault. Results cover retained jobs, not a permanent job history, and pages are not a single consistent snapshot. This can help recover a job ID after an uncertain InitiateJob response; a missing job does not prove the request failed. The final count is records listed, not a deduplicated count of unique jobs.
Uses AWS Signature Version 4 with service glacier. Set the region once; the example builds the commercial AWS endpoint. Other partitions require the appropriate endpoint suffix. /-/ selects the signing account; change the vault name and IDs to your own resources. Load private qa_data/aws/glacier.json with string fields access_key, secret_key, and session_token for temporary credentials. Prefer short-lived role credentials. This sample does not discover profiles or refresh credentials. TLS certificate verification is enabled explicitly.
Checks transport completion, the operation-specific HTTP status, and parsed data separately. Inspect full diagnostics privately. Renew expired credentials; use bounded backoff with jitter for retryable reads. Uploads and job initiation can succeed before a connection fails, so do not blindly resubmit them. Configure IAM permissions for only the required operations and vault resources.
Chilkat Delphi DLL Downloads
var
statusFilter: PWideChar;
completedFilter: PWideChar;
success: Boolean;
credentials: HCkJsonObject;
region: PWideChar;
endpoint: HCkStringBuilder;
aws: HCkAuthAws;
rest: HCkRest;
connection: HCkSocket;
result: HCkJsonObject;
error: HCkJsonObject;
responseBody: HCkStringBuilder;
recordsListed: Integer;
seenMarkers: HCkHashtable;
marker: PWideChar;
more: Boolean;
page: Integer;
i: Integer;
begin
// Optional filters. An empty string means OMIT the filter, not false.
// statusFilter: "", "InProgress", "Succeeded", or "Failed" (case-sensitive).
// completedFilter: "", "true", or "false" (lowercase on the wire).
// Examples: "Failed" + "true" lists failed completed jobs;
// "" + "true" includes both succeeded and failed completed jobs.
statusFilter := '';
completedFilter := '';
if ((statusFilter <> '') and (statusFilter <> 'InProgress') and (statusFilter <> 'Succeeded') and (statusFilter <> 'Failed')) then
begin
Memo1.Lines.Add('Invalid status filter. Use InProgress, Succeeded, Failed, or an empty string.');
Exit;
end;
if ((completedFilter <> '') and (completedFilter <> 'true') and (completedFilter <> 'false')) then
begin
Memo1.Lines.Add('Invalid completion filter. Use true, false, or an empty string.');
Exit;
end;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success := False;
// Private configuration, not a file in public web content or source control.
// Load current IAM credentials authorized for the Glacier operation.
credentials := CkJsonObject_Create();
CkJsonObject_putStrict(credentials,True);
success := CkJsonObject_LoadFile(credentials,'qa_data/aws/glacier.json');
if (success <> True) then
begin
Memo1.Lines.Add('Could not load private AWS credentials.');
Exit;
end;
if ((CkJsonObject_JsonTypeOf(credentials,'access_key') <> 1) or (CkJsonObject__stringOf(credentials,'access_key') = '')) then
begin
Memo1.Lines.Add('Missing or invalid access_key.');
Exit;
end;
if ((CkJsonObject_JsonTypeOf(credentials,'secret_key') <> 1) or (CkJsonObject__stringOf(credentials,'secret_key') = '')) then
begin
Memo1.Lines.Add('Missing or invalid secret_key.');
Exit;
end;
// Set this once to the region containing the vault.
region := 'us-west-2';
endpoint := CkStringBuilder_Create();
CkStringBuilder_Append(endpoint,'glacier.');
CkStringBuilder_Append(endpoint,region);
CkStringBuilder_Append(endpoint,'.amazonaws.com');
aws := CkAuthAws_Create();
CkAuthAws_putAccessKey(aws,CkJsonObject__stringOf(credentials,'access_key'));
CkAuthAws_putSecretKey(aws,CkJsonObject__stringOf(credentials,'secret_key'));
CkAuthAws_putRegion(aws,region);
CkAuthAws_putServiceName(aws,'glacier');
CkAuthAws_putSignatureVersion(aws,4);
rest := CkRest_Create();
CkRest_putConnectTimeoutMs(rest,20000);
CkRest_putIdleTimeoutMs(rest,60000);
success := CkRest_SetAuthAws(rest,aws);
if (success <> True) then
begin
Memo1.Lines.Add('Could not configure AWS signing.');
Exit;
end;
// Temporary IAM/STS credentials require their session token on every signed request.
// Include the token in the signed query. Keep request URLs and diagnostics private.
// Leave session_token absent or empty only for credentials that do not have one.
if (CkJsonObject_HasMember(credentials,'session_token') = True) then
begin
if (CkJsonObject_JsonTypeOf(credentials,'session_token') <> 1) then
begin
Memo1.Lines.Add('session_token must be a string.');
Exit;
end;
if (CkJsonObject__stringOf(credentials,'session_token') <> '') then
begin
success := CkRest_AddQueryParam(rest,'X-Amz-Security-Token',CkJsonObject__stringOf(credentials,'session_token'));
if (success <> True) then
begin
Memo1.Lines.Add('Could not set the session-token parameter.');
Exit;
end;
end;
end;
// Supply a Socket to explicitly enable TLS certificate verification.
connection := CkSocket_Create();
CkSocket_putRequireSslCertVerify(connection,True);
CkSocket_putMaxReadIdleMs(connection,60000);
CkSocket_putMaxSendIdleMs(connection,60000);
success := CkSocket_Connect(connection,CkStringBuilder__getAsString(endpoint),443,True,20000);
if (success <> True) then
begin
Memo1.Lines.Add('TLS connection failed; inspect diagnostics privately.');
Exit;
end;
success := CkRest_UseConnection(rest,connection,True);
if (success <> True) then
begin
Memo1.Lines.Add('Could not attach the TLS connection.');
Exit;
end;
success := CkRest_AddHeader(rest,'x-amz-glacier-version','2012-06-01');
if (success <> True) then
begin
Memo1.Lines.Add('Could not set x-amz-glacier-version.');
Exit;
end;
// A hyphen selects the account belonging to the signing credentials.
// Use the original, URL-safe vault name and IDs returned by Glacier.
success := CkRest_AddPathParam(rest,'{vault}','chilkat');
if (success <> True) then
begin
Memo1.Lines.Add('Could not set vault name.');
Exit;
end;
result := CkJsonObject_Create();
CkJsonObject_putStrict(result,True);
error := CkJsonObject_Create();
CkJsonObject_putStrict(error,True);
responseBody := CkStringBuilder_Create();
// Both filters, if supplied, apply together. Keep them on every page.
if (statusFilter <> '') then
begin
success := CkRest_AddQueryParam(rest,'statuscode',statusFilter);
if (success <> True) then
begin
Memo1.Lines.Add('Could not set statuscode filter.');
Exit;
end;
end;
if (completedFilter <> '') then
begin
success := CkRest_AddQueryParam(rest,'completed',completedFilter);
if (success <> True) then
begin
Memo1.Lines.Add('Could not set completed filter.');
Exit;
end;
end;
recordsListed := 0;
success := CkRest_AddQueryParam(rest,'limit','50');
if (success <> True) then
begin
Memo1.Lines.Add('Could not set page limit.');
Exit;
end;
seenMarkers := CkHashtable_Create();
marker := '';
more := True;
page := 0;
while (more = True) do
begin
if (page = 1000) then
begin
Memo1.Lines.Add('Page limit reached; listing is incomplete.');
Exit;
end;
page := page + 1;
if (marker <> '') then
begin
success := CkRest_AddQueryParam(rest,'marker',marker);
if (success <> True) then
begin
Memo1.Lines.Add('Could not set marker.');
Exit;
end;
end;
success := CkRest_FullRequestNoBodySb(rest,'GET','/-/vaults/{vault}/jobs',responseBody);
if (success <> True) then
begin
Memo1.Lines.Add('Request did not complete; inspect diagnostics privately. Check state before retrying a change.');
Exit;
end;
if (CkRest_getResponseStatusCode(rest) <> 200) then
begin
Memo1.Lines.Add('Glacier HTTP status: ' + IntToStr(CkRest_getResponseStatusCode(rest)));
success := CkJsonObject_LoadSb(error,responseBody);
if (success = True) then
begin
if (CkJsonObject_JsonTypeOf(error,'code') = 1) then
begin
Memo1.Lines.Add('AWS error code: ' + CkJsonObject__stringOf(error,'code'));
end;
end;
Memo1.Lines.Add('AWS request ID: ' + CkRest__responseHdrByName(rest,'x-amzn-RequestId'));
// Inspect full errors privately. An HTTP error is not a successful operation.
Exit;
end;
success := CkJsonObject_LoadSb(result,responseBody);
if (success <> True) then
begin
Memo1.Lines.Add('Expected valid JSON response.');
Exit;
end;
if (CkJsonObject_JsonTypeOf(result,'JobList') <> 4) then
begin
Memo1.Lines.Add('Missing or invalid JobList.');
Exit;
end;
i := 0;
while (i < CkJsonObject_SizeOfArray(result,'JobList')) do
begin
CkJsonObject_putI(result,i);
if (CkJsonObject_JsonTypeOf(result,'JobList[i].JobId') <> 1) then
begin
Memo1.Lines.Add('Missing or invalid JobList[i].JobId.');
Exit;
end;
if (CkJsonObject__stringOf(result,'JobList[i].JobId') = '') then
begin
Memo1.Lines.Add('Empty JobList[i].JobId.');
Exit;
end;
if (CkJsonObject_JsonTypeOf(result,'JobList[i].Action') <> 1) then
begin
Memo1.Lines.Add('Missing or invalid JobList[i].Action.');
Exit;
end;
if (CkJsonObject__stringOf(result,'JobList[i].Action') = '') then
begin
Memo1.Lines.Add('Empty JobList[i].Action.');
Exit;
end;
if (CkJsonObject_JsonTypeOf(result,'JobList[i].StatusCode') <> 1) then
begin
Memo1.Lines.Add('Missing or invalid JobList[i].StatusCode.');
Exit;
end;
if (CkJsonObject__stringOf(result,'JobList[i].StatusCode') = '') then
begin
Memo1.Lines.Add('Empty JobList[i].StatusCode.');
Exit;
end;
if (CkJsonObject_JsonTypeOf(result,'JobList[i].Completed') <> 5) then
begin
Memo1.Lines.Add('Missing or invalid JobList[i].Completed.');
Exit;
end;
Memo1.Lines.Add('Job ID: ' + CkJsonObject__stringOf(result,'JobList[i].JobId'));
Memo1.Lines.Add('Action: ' + CkJsonObject__stringOf(result,'JobList[i].Action'));
Memo1.Lines.Add('Status: ' + CkJsonObject__stringOf(result,'JobList[i].StatusCode'));
Memo1.Lines.Add('Completed: ' + CkJsonObject__stringOf(result,'JobList[i].Completed'));
if (CkJsonObject_JsonTypeOf(result,'JobList[i].CreationDate') = 1) then
begin
Memo1.Lines.Add('Created: ' + CkJsonObject__stringOf(result,'JobList[i].CreationDate'));
end;
if (CkJsonObject_JsonTypeOf(result,'JobList[i].CompletionDate') = 1) then
begin
Memo1.Lines.Add('Finished: ' + CkJsonObject__stringOf(result,'JobList[i].CompletionDate'));
end;
if (CkJsonObject_JsonTypeOf(result,'JobList[i].ArchiveId') = 1) then
begin
Memo1.Lines.Add('Archive ID: ' + CkJsonObject__stringOf(result,'JobList[i].ArchiveId'));
end;
if (CkJsonObject_JsonTypeOf(result,'JobList[i].ArchiveSizeInBytes') = 2) then
begin
Memo1.Lines.Add('Archive bytes: ' + CkJsonObject__stringOf(result,'JobList[i].ArchiveSizeInBytes'));
end;
if (CkJsonObject_JsonTypeOf(result,'JobList[i].InventorySizeInBytes') = 2) then
begin
Memo1.Lines.Add('Inventory bytes: ' + CkJsonObject__stringOf(result,'JobList[i].InventorySizeInBytes'));
end;
if (CkJsonObject_JsonTypeOf(result,'JobList[i].Tier') = 1) then
begin
Memo1.Lines.Add('Retrieval tier: ' + CkJsonObject__stringOf(result,'JobList[i].Tier'));
end;
// Completed=true alone does not mean success. Do not download failed jobs.
if ((CkJsonObject_BoolOf(result,'JobList[i].Completed') = True) and (CkJsonObject__stringOf(result,'JobList[i].StatusCode') = 'Succeeded')) then
begin
Memo1.Lines.Add('Job succeeded; retrieve output promptly.');
end
else
begin
if (CkJsonObject__stringOf(result,'JobList[i].StatusCode') = 'Failed') then
begin
Memo1.Lines.Add('Job failed. Inspect StatusMessage privately; continue listing other jobs.');
end
else
begin
Memo1.Lines.Add('Job is not confirmed successful. Check its status before retrieving output.');
end;
end;
recordsListed := recordsListed + 1;
Memo1.Lines.Add('---');
i := i + 1;
end;
more := False;
if (CkJsonObject_JsonTypeOf(result,'Marker') = 1) then
begin
marker := CkJsonObject__stringOf(result,'Marker');
if (marker = '') then
begin
Memo1.Lines.Add('Empty marker; listing is incomplete.');
Exit;
end;
if (CkHashtable_Contains(seenMarkers,marker) = True) then
begin
Memo1.Lines.Add('Repeated marker; listing is incomplete.');
Exit;
end;
success := CkHashtable_AddStr(seenMarkers,marker,'seen');
if (success <> True) then
begin
Memo1.Lines.Add('Could not track pagination.');
Exit;
end;
more := True;
end
else
begin
if (CkJsonObject_JsonTypeOf(result,'Marker') <> 6) then
begin
Memo1.Lines.Add('Missing or invalid Marker; listing is incomplete.');
Exit;
end;
end;
end;
success := CkRest_RemoveQueryParam(rest,'limit');
if (success <> True) then
begin
Memo1.Lines.Add('Could not clear limit.');
Exit;
end;
if (marker <> '') then
begin
success := CkRest_RemoveQueryParam(rest,'marker');
if (success <> True) then
begin
Memo1.Lines.Add('Could not clear marker.');
Exit;
end;
end;
Memo1.Lines.Add('Job listing complete. Records listed: ' + IntToStr(recordsListed));
CkJsonObject_Dispose(credentials);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkJsonObject_Dispose(result);
CkJsonObject_Dispose(error);
CkStringBuilder_Dispose(responseBody);
CkHashtable_Dispose(seenMarkers);