Sample code for 30+ languages & platforms
PowerBuilder Requires Chilkat v11.6.0+

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.

AWS reference

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
string ls_StatusFilter
string ls_CompletedFilter
long li_Success
oleobject loo_Credentials
string ls_Region
oleobject loo_Endpoint
oleobject loo_Aws
oleobject loo_Rest
oleobject loo_Connection
oleobject loo_Result
oleobject loo_Error
oleobject loo_ResponseBody
long li_RecordsListed
oleobject loo_SeenMarkers
string ls_Marker
long li_More
long li_Page
long i

//  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.
ls_StatusFilter = ""
ls_CompletedFilter = ""
if (ls_StatusFilter <> "") AND (ls_StatusFilter <> "InProgress") AND (ls_StatusFilter <> "Succeeded") AND (ls_StatusFilter <> "Failed") then
    Write-Debug "Invalid status filter. Use InProgress, Succeeded, Failed, or an empty string."
    return
end if

if (ls_CompletedFilter <> "") AND (ls_CompletedFilter <> "true") AND (ls_CompletedFilter <> "false") then
    Write-Debug "Invalid completion filter. Use true, false, or an empty string."
    return
end if

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
li_Success = 0
//  Private configuration, not a file in public web content or source control.
//  Load current IAM credentials authorized for the Glacier operation.
loo_Credentials = create oleobject
li_rc = loo_Credentials.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
    destroy loo_Credentials
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Credentials.Strict = 1
li_Success = loo_Credentials.LoadFile("qa_data/aws/glacier.json")
if li_Success <> 1 then
    Write-Debug "Could not load private AWS credentials."
    destroy loo_Credentials
    return
end if

if (loo_Credentials.JsonTypeOf("access_key") <> 1) OR (loo_Credentials.StringOf("access_key") = "") then
    Write-Debug "Missing or invalid access_key."
    destroy loo_Credentials
    return
end if

if (loo_Credentials.JsonTypeOf("secret_key") <> 1) OR (loo_Credentials.StringOf("secret_key") = "") then
    Write-Debug "Missing or invalid secret_key."
    destroy loo_Credentials
    return
end if

//  Set this once to the region containing the vault.
ls_Region = "us-west-2"
loo_Endpoint = create oleobject
li_rc = loo_Endpoint.ConnectToNewObject("Chilkat.StringBuilder")

loo_Endpoint.Append("glacier.")
loo_Endpoint.Append(ls_Region)
loo_Endpoint.Append(".amazonaws.com")
loo_Aws = create oleobject
li_rc = loo_Aws.ConnectToNewObject("Chilkat.AuthAws")

loo_Aws.AccessKey = loo_Credentials.StringOf("access_key")
loo_Aws.SecretKey = loo_Credentials.StringOf("secret_key")
loo_Aws.Region = ls_Region
loo_Aws.ServiceName = "glacier"
loo_Aws.SignatureVersion = 4
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")

loo_Rest.ConnectTimeoutMs = 20000
loo_Rest.IdleTimeoutMs = 60000
li_Success = loo_Rest.SetAuthAws(loo_Aws)
if li_Success <> 1 then
    Write-Debug "Could not configure AWS signing."
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    return
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 loo_Credentials.HasMember("session_token") = 1 then
    if loo_Credentials.JsonTypeOf("session_token") <> 1 then
        Write-Debug "session_token must be a string."
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        return
    end if

    if loo_Credentials.StringOf("session_token") <> "" then
        li_Success = loo_Rest.AddQueryParam("X-Amz-Security-Token",loo_Credentials.StringOf("session_token"))
        if li_Success <> 1 then
            Write-Debug "Could not set the session-token parameter."
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            return
        end if

    end if

end if

//  Supply a Socket to explicitly enable TLS certificate verification.
loo_Connection = create oleobject
li_rc = loo_Connection.ConnectToNewObject("Chilkat.Socket")

loo_Connection.RequireSslCertVerify = 1
loo_Connection.MaxReadIdleMs = 60000
loo_Connection.MaxSendIdleMs = 60000
li_Success = loo_Connection.Connect(loo_Endpoint.GetAsString(),443,1,20000)
if li_Success <> 1 then
    Write-Debug "TLS connection failed; inspect diagnostics privately."
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    return
end if

li_Success = loo_Rest.UseConnection(loo_Connection,1)
if li_Success <> 1 then
    Write-Debug "Could not attach the TLS connection."
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    return
end if

li_Success = loo_Rest.AddHeader("x-amz-glacier-version","2012-06-01")
if li_Success <> 1 then
    Write-Debug "Could not set x-amz-glacier-version."
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    return
end if

//  A hyphen selects the account belonging to the signing credentials.
//  Use the original, URL-safe vault name and IDs returned by Glacier.
li_Success = loo_Rest.AddPathParam("{vault}","chilkat")
if li_Success <> 1 then
    Write-Debug "Could not set vault name."
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    return
end if

loo_Result = create oleobject
li_rc = loo_Result.ConnectToNewObject("Chilkat.JsonObject")

loo_Result.Strict = 1
loo_Error = create oleobject
li_rc = loo_Error.ConnectToNewObject("Chilkat.JsonObject")

loo_Error.Strict = 1
loo_ResponseBody = create oleobject
li_rc = loo_ResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

//  Both filters, if supplied, apply together. Keep them on every page.
if ls_StatusFilter <> "" then
    li_Success = loo_Rest.AddQueryParam("statuscode",ls_StatusFilter)
    if li_Success <> 1 then
        Write-Debug "Could not set statuscode filter."
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Result
        destroy loo_Error
        destroy loo_ResponseBody
        return
    end if

end if

if ls_CompletedFilter <> "" then
    li_Success = loo_Rest.AddQueryParam("completed",ls_CompletedFilter)
    if li_Success <> 1 then
        Write-Debug "Could not set completed filter."
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Result
        destroy loo_Error
        destroy loo_ResponseBody
        return
    end if

end if

li_RecordsListed = 0
li_Success = loo_Rest.AddQueryParam("limit","50")
if li_Success <> 1 then
    Write-Debug "Could not set page limit."
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Result
    destroy loo_Error
    destroy loo_ResponseBody
    return
end if

loo_SeenMarkers = create oleobject
li_rc = loo_SeenMarkers.ConnectToNewObject("Chilkat.Hashtable")

ls_Marker = ""
li_More = 1
li_Page = 0
do while (li_More = 1)
    if li_Page = 1000 then
        Write-Debug "Page limit reached; listing is incomplete."
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Result
        destroy loo_Error
        destroy loo_ResponseBody
        destroy loo_SeenMarkers
        return
    end if

    li_Page = li_Page + 1
    if ls_Marker <> "" then
        li_Success = loo_Rest.AddQueryParam("marker",ls_Marker)
        if li_Success <> 1 then
            Write-Debug "Could not set marker."
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            destroy loo_Connection
            destroy loo_Result
            destroy loo_Error
            destroy loo_ResponseBody
            destroy loo_SeenMarkers
            return
        end if

    end if

    li_Success = loo_Rest.FullRequestNoBodySb("GET","/-/vaults/{vault}/jobs",loo_ResponseBody)
    if li_Success <> 1 then
        Write-Debug "Request did not complete; inspect diagnostics privately. Check state before retrying a change."
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Result
        destroy loo_Error
        destroy loo_ResponseBody
        destroy loo_SeenMarkers
        return
    end if

    if loo_Rest.ResponseStatusCode <> 200 then
        Write-Debug "Glacier HTTP status: " + string(loo_Rest.ResponseStatusCode)
        li_Success = loo_Error.LoadSb(loo_ResponseBody)
        if li_Success = 1 then
            if loo_Error.JsonTypeOf("code") = 1 then
                Write-Debug "AWS error code: " + loo_Error.StringOf("code")
            end if

        end if

        Write-Debug "AWS request ID: " + loo_Rest.ResponseHdrByName("x-amzn-RequestId")
        //  Inspect full errors privately. An HTTP error is not a successful operation.
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Result
        destroy loo_Error
        destroy loo_ResponseBody
        destroy loo_SeenMarkers
        return
    end if

    li_Success = loo_Result.LoadSb(loo_ResponseBody)
    if li_Success <> 1 then
        Write-Debug "Expected valid JSON response."
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Result
        destroy loo_Error
        destroy loo_ResponseBody
        destroy loo_SeenMarkers
        return
    end if

    if loo_Result.JsonTypeOf("JobList") <> 4 then
        Write-Debug "Missing or invalid JobList."
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Result
        destroy loo_Error
        destroy loo_ResponseBody
        destroy loo_SeenMarkers
        return
    end if

    i = 0
    do while (i < loo_Result.SizeOfArray("JobList"))
        loo_Result.I = i
        if loo_Result.JsonTypeOf("JobList[i].JobId") <> 1 then
            Write-Debug "Missing or invalid JobList[i].JobId."
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            destroy loo_Connection
            destroy loo_Result
            destroy loo_Error
            destroy loo_ResponseBody
            destroy loo_SeenMarkers
            return
        end if

        if loo_Result.StringOf("JobList[i].JobId") = "" then
            Write-Debug "Empty JobList[i].JobId."
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            destroy loo_Connection
            destroy loo_Result
            destroy loo_Error
            destroy loo_ResponseBody
            destroy loo_SeenMarkers
            return
        end if

        if loo_Result.JsonTypeOf("JobList[i].Action") <> 1 then
            Write-Debug "Missing or invalid JobList[i].Action."
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            destroy loo_Connection
            destroy loo_Result
            destroy loo_Error
            destroy loo_ResponseBody
            destroy loo_SeenMarkers
            return
        end if

        if loo_Result.StringOf("JobList[i].Action") = "" then
            Write-Debug "Empty JobList[i].Action."
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            destroy loo_Connection
            destroy loo_Result
            destroy loo_Error
            destroy loo_ResponseBody
            destroy loo_SeenMarkers
            return
        end if

        if loo_Result.JsonTypeOf("JobList[i].StatusCode") <> 1 then
            Write-Debug "Missing or invalid JobList[i].StatusCode."
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            destroy loo_Connection
            destroy loo_Result
            destroy loo_Error
            destroy loo_ResponseBody
            destroy loo_SeenMarkers
            return
        end if

        if loo_Result.StringOf("JobList[i].StatusCode") = "" then
            Write-Debug "Empty JobList[i].StatusCode."
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            destroy loo_Connection
            destroy loo_Result
            destroy loo_Error
            destroy loo_ResponseBody
            destroy loo_SeenMarkers
            return
        end if

        if loo_Result.JsonTypeOf("JobList[i].Completed") <> 5 then
            Write-Debug "Missing or invalid JobList[i].Completed."
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            destroy loo_Connection
            destroy loo_Result
            destroy loo_Error
            destroy loo_ResponseBody
            destroy loo_SeenMarkers
            return
        end if

        Write-Debug "Job ID: " + loo_Result.StringOf("JobList[i].JobId")
        Write-Debug "Action: " + loo_Result.StringOf("JobList[i].Action")
        Write-Debug "Status: " + loo_Result.StringOf("JobList[i].StatusCode")
        Write-Debug "Completed: " + loo_Result.StringOf("JobList[i].Completed")
        if loo_Result.JsonTypeOf("JobList[i].CreationDate") = 1 then
            Write-Debug "Created: " + loo_Result.StringOf("JobList[i].CreationDate")
        end if

        if loo_Result.JsonTypeOf("JobList[i].CompletionDate") = 1 then
            Write-Debug "Finished: " + loo_Result.StringOf("JobList[i].CompletionDate")
        end if

        if loo_Result.JsonTypeOf("JobList[i].ArchiveId") = 1 then
            Write-Debug "Archive ID: " + loo_Result.StringOf("JobList[i].ArchiveId")
        end if

        if loo_Result.JsonTypeOf("JobList[i].ArchiveSizeInBytes") = 2 then
            Write-Debug "Archive bytes: " + loo_Result.StringOf("JobList[i].ArchiveSizeInBytes")
        end if

        if loo_Result.JsonTypeOf("JobList[i].InventorySizeInBytes") = 2 then
            Write-Debug "Inventory bytes: " + loo_Result.StringOf("JobList[i].InventorySizeInBytes")
        end if

        if loo_Result.JsonTypeOf("JobList[i].Tier") = 1 then
            Write-Debug "Retrieval tier: " + loo_Result.StringOf("JobList[i].Tier")
        end if

        //  Completed=true alone does not mean success. Do not download failed jobs.
        if (loo_Result.BoolOf("JobList[i].Completed") = 1) AND (loo_Result.StringOf("JobList[i].StatusCode") = "Succeeded") then
            Write-Debug "Job succeeded; retrieve output promptly."
        else
            if loo_Result.StringOf("JobList[i].StatusCode") = "Failed" then
                Write-Debug "Job failed. Inspect StatusMessage privately; continue listing other jobs."
            else
                Write-Debug "Job is not confirmed successful. Check its status before retrieving output."
            end if

        end if

        li_RecordsListed = li_RecordsListed + 1
        Write-Debug "---"
        i = i + 1
    loop
    li_More = 0
    if loo_Result.JsonTypeOf("Marker") = 1 then
        ls_Marker = loo_Result.StringOf("Marker")
        if ls_Marker = "" then
            Write-Debug "Empty marker; listing is incomplete."
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            destroy loo_Connection
            destroy loo_Result
            destroy loo_Error
            destroy loo_ResponseBody
            destroy loo_SeenMarkers
            return
        end if

        if loo_SeenMarkers.Contains(ls_Marker) = 1 then
            Write-Debug "Repeated marker; listing is incomplete."
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            destroy loo_Connection
            destroy loo_Result
            destroy loo_Error
            destroy loo_ResponseBody
            destroy loo_SeenMarkers
            return
        end if

        li_Success = loo_SeenMarkers.AddStr(ls_Marker,"seen")
        if li_Success <> 1 then
            Write-Debug "Could not track pagination."
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            destroy loo_Connection
            destroy loo_Result
            destroy loo_Error
            destroy loo_ResponseBody
            destroy loo_SeenMarkers
            return
        end if

        li_More = 1
    else
        if loo_Result.JsonTypeOf("Marker") <> 6 then
            Write-Debug "Missing or invalid Marker; listing is incomplete."
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            destroy loo_Connection
            destroy loo_Result
            destroy loo_Error
            destroy loo_ResponseBody
            destroy loo_SeenMarkers
            return
        end if

    end if

loop
li_Success = loo_Rest.RemoveQueryParam("limit")
if li_Success <> 1 then
    Write-Debug "Could not clear limit."
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Result
    destroy loo_Error
    destroy loo_ResponseBody
    destroy loo_SeenMarkers
    return
end if

if ls_Marker <> "" then
    li_Success = loo_Rest.RemoveQueryParam("marker")
    if li_Success <> 1 then
        Write-Debug "Could not clear marker."
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Result
        destroy loo_Error
        destroy loo_ResponseBody
        destroy loo_SeenMarkers
        return
    end if

end if

Write-Debug "Job listing complete. Records listed: " + string(li_RecordsListed)


destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
destroy loo_Result
destroy loo_Error
destroy loo_ResponseBody
destroy loo_SeenMarkers