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 Visual Basic 6.0 Downloads
' 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.
Dim statusFilter As String
statusFilter = ""
Dim completedFilter As String
completedFilter = ""
If ((statusFilter <> "") And (statusFilter <> "InProgress") And (statusFilter <> "Succeeded") And (statusFilter <> "Failed")) Then
Debug.Print "Invalid status filter. Use InProgress, Succeeded, Failed, or an empty string."
Exit Sub
End If
If ((completedFilter <> "") And (completedFilter <> "true") And (completedFilter <> "false")) Then
Debug.Print "Invalid completion filter. Use true, false, or an empty string."
Exit Sub
End If
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim success As Long
success = 0
' Private configuration, not a file in public web content or source control.
' Load current IAM credentials authorized for the Glacier operation.
Dim credentials As New ChilkatJsonObject
credentials.Strict = 1
success = credentials.LoadFile("qa_data/aws/glacier.json")
If (success <> 1) Then
Debug.Print "Could not load private AWS credentials."
Exit Sub
End If
If ((credentials.JsonTypeOf("access_key") <> 1) Or (credentials.StringOf("access_key") = "")) Then
Debug.Print "Missing or invalid access_key."
Exit Sub
End If
If ((credentials.JsonTypeOf("secret_key") <> 1) Or (credentials.StringOf("secret_key") = "")) Then
Debug.Print "Missing or invalid secret_key."
Exit Sub
End If
' Set this once to the region containing the vault.
Dim region As String
region = "us-west-2"
Dim endpoint As New ChilkatStringBuilder
success = endpoint.Append("glacier.")
success = endpoint.Append(region)
success = endpoint.Append(".amazonaws.com")
Dim aws As New ChilkatAuthAws
aws.AccessKey = credentials.StringOf("access_key")
aws.SecretKey = credentials.StringOf("secret_key")
aws.Region = region
aws.ServiceName = "glacier"
aws.SignatureVersion = 4
Dim rest As New ChilkatRest
rest.ConnectTimeoutMs = 20000
rest.IdleTimeoutMs = 60000
success = rest.SetAuthAws(aws)
If (success <> 1) Then
Debug.Print "Could not configure AWS signing."
Exit Sub
End If
' 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 (credentials.HasMember("session_token") = 1) Then
If (credentials.JsonTypeOf("session_token") <> 1) Then
Debug.Print "session_token must be a string."
Exit Sub
End If
If (credentials.StringOf("session_token") <> "") Then
success = rest.AddQueryParam("X-Amz-Security-Token",credentials.StringOf("session_token"))
If (success <> 1) Then
Debug.Print "Could not set the session-token parameter."
Exit Sub
End If
End If
End If
' Supply a Socket to explicitly enable TLS certificate verification.
Dim connection As New ChilkatSocket
connection.RequireSslCertVerify = 1
connection.MaxReadIdleMs = 60000
connection.MaxSendIdleMs = 60000
success = connection.Connect(endpoint.GetAsString(),443,1,20000)
If (success <> 1) Then
Debug.Print "TLS connection failed; inspect diagnostics privately."
Exit Sub
End If
success = rest.UseConnection(connection,1)
If (success <> 1) Then
Debug.Print "Could not attach the TLS connection."
Exit Sub
End If
success = rest.AddHeader("x-amz-glacier-version","2012-06-01")
If (success <> 1) Then
Debug.Print "Could not set x-amz-glacier-version."
Exit Sub
End If
' A hyphen selects the account belonging to the signing credentials.
' Use the original, URL-safe vault name and IDs returned by Glacier.
success = rest.AddPathParam("{vault}","chilkat")
If (success <> 1) Then
Debug.Print "Could not set vault name."
Exit Sub
End If
Dim result As New ChilkatJsonObject
result.Strict = 1
Dim error As New ChilkatJsonObject
error.Strict = 1
Dim responseBody As New ChilkatStringBuilder
' Both filters, if supplied, apply together. Keep them on every page.
If (statusFilter <> "") Then
success = rest.AddQueryParam("statuscode",statusFilter)
If (success <> 1) Then
Debug.Print "Could not set statuscode filter."
Exit Sub
End If
End If
If (completedFilter <> "") Then
success = rest.AddQueryParam("completed",completedFilter)
If (success <> 1) Then
Debug.Print "Could not set completed filter."
Exit Sub
End If
End If
Dim recordsListed As Long
recordsListed = 0
success = rest.AddQueryParam("limit","50")
If (success <> 1) Then
Debug.Print "Could not set page limit."
Exit Sub
End If
Dim seenMarkers As New ChilkatHashtable
Dim marker As String
marker = ""
Dim more As Long
more = 1
Dim page As Long
page = 0
Do While (more = 1)
If (page = 1000) Then
Debug.Print "Page limit reached; listing is incomplete."
Exit Sub
End If
page = page + 1
If (marker <> "") Then
success = rest.AddQueryParam("marker",marker)
If (success <> 1) Then
Debug.Print "Could not set marker."
Exit Sub
End If
End If
success = rest.FullRequestNoBodySb("GET","/-/vaults/{vault}/jobs",responseBody)
If (success <> 1) Then
Debug.Print "Request did not complete; inspect diagnostics privately. Check state before retrying a change."
Exit Sub
End If
If (rest.ResponseStatusCode <> 200) Then
Debug.Print "Glacier HTTP status: " & rest.ResponseStatusCode
success = error.LoadSb(responseBody)
If (success = 1) Then
If (error.JsonTypeOf("code") = 1) Then
Debug.Print "AWS error code: " & error.StringOf("code")
End If
End If
Debug.Print "AWS request ID: " & rest.ResponseHdrByName("x-amzn-RequestId")
' Inspect full errors privately. An HTTP error is not a successful operation.
Exit Sub
End If
success = result.LoadSb(responseBody)
If (success <> 1) Then
Debug.Print "Expected valid JSON response."
Exit Sub
End If
If (result.JsonTypeOf("JobList") <> 4) Then
Debug.Print "Missing or invalid JobList."
Exit Sub
End If
Dim i As Long
i = 0
Do While (i < result.SizeOfArray("JobList"))
result.I = i
If (result.JsonTypeOf("JobList[i].JobId") <> 1) Then
Debug.Print "Missing or invalid JobList[i].JobId."
Exit Sub
End If
If (result.StringOf("JobList[i].JobId") = "") Then
Debug.Print "Empty JobList[i].JobId."
Exit Sub
End If
If (result.JsonTypeOf("JobList[i].Action") <> 1) Then
Debug.Print "Missing or invalid JobList[i].Action."
Exit Sub
End If
If (result.StringOf("JobList[i].Action") = "") Then
Debug.Print "Empty JobList[i].Action."
Exit Sub
End If
If (result.JsonTypeOf("JobList[i].StatusCode") <> 1) Then
Debug.Print "Missing or invalid JobList[i].StatusCode."
Exit Sub
End If
If (result.StringOf("JobList[i].StatusCode") = "") Then
Debug.Print "Empty JobList[i].StatusCode."
Exit Sub
End If
If (result.JsonTypeOf("JobList[i].Completed") <> 5) Then
Debug.Print "Missing or invalid JobList[i].Completed."
Exit Sub
End If
Debug.Print "Job ID: " & result.StringOf("JobList[i].JobId")
Debug.Print "Action: " & result.StringOf("JobList[i].Action")
Debug.Print "Status: " & result.StringOf("JobList[i].StatusCode")
Debug.Print "Completed: " & result.StringOf("JobList[i].Completed")
If (result.JsonTypeOf("JobList[i].CreationDate") = 1) Then
Debug.Print "Created: " & result.StringOf("JobList[i].CreationDate")
End If
If (result.JsonTypeOf("JobList[i].CompletionDate") = 1) Then
Debug.Print "Finished: " & result.StringOf("JobList[i].CompletionDate")
End If
If (result.JsonTypeOf("JobList[i].ArchiveId") = 1) Then
Debug.Print "Archive ID: " & result.StringOf("JobList[i].ArchiveId")
End If
If (result.JsonTypeOf("JobList[i].ArchiveSizeInBytes") = 2) Then
Debug.Print "Archive bytes: " & result.StringOf("JobList[i].ArchiveSizeInBytes")
End If
If (result.JsonTypeOf("JobList[i].InventorySizeInBytes") = 2) Then
Debug.Print "Inventory bytes: " & result.StringOf("JobList[i].InventorySizeInBytes")
End If
If (result.JsonTypeOf("JobList[i].Tier") = 1) Then
Debug.Print "Retrieval tier: " & result.StringOf("JobList[i].Tier")
End If
' Completed=true alone does not mean success. Do not download failed jobs.
If ((result.BoolOf("JobList[i].Completed") = 1) And (result.StringOf("JobList[i].StatusCode") = "Succeeded")) Then
Debug.Print "Job succeeded; retrieve output promptly."
Else
If (result.StringOf("JobList[i].StatusCode") = "Failed") Then
Debug.Print "Job failed. Inspect StatusMessage privately; continue listing other jobs."
Else
Debug.Print "Job is not confirmed successful. Check its status before retrieving output."
End If
End If
recordsListed = recordsListed + 1
Debug.Print "---"
i = i + 1
Loop
more = 0
If (result.JsonTypeOf("Marker") = 1) Then
marker = result.StringOf("Marker")
If (marker = "") Then
Debug.Print "Empty marker; listing is incomplete."
Exit Sub
End If
If (seenMarkers.Contains(marker) = 1) Then
Debug.Print "Repeated marker; listing is incomplete."
Exit Sub
End If
success = seenMarkers.AddStr(marker,"seen")
If (success <> 1) Then
Debug.Print "Could not track pagination."
Exit Sub
End If
more = 1
Else
If (result.JsonTypeOf("Marker") <> 6) Then
Debug.Print "Missing or invalid Marker; listing is incomplete."
Exit Sub
End If
End If
Loop
success = rest.RemoveQueryParam("limit")
If (success <> 1) Then
Debug.Print "Could not clear limit."
Exit Sub
End If
If (marker <> "") Then
success = rest.RemoveQueryParam("marker")
If (success <> 1) Then
Debug.Print "Could not clear marker."
Exit Sub
End If
End If
Debug.Print "Job listing complete. Records listed: " & recordsListed