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

Amazon S3: Read, Merge, and Remove Object Tags

See more S3 - REST Examples

Select read, merge, remove-one, or delete-all. Merge adds or replaces one named tag while preserving other tags from GetObjectTagging. Remove-one rebuilds the set without that key; delete-all uses DeleteObjectTagging. An empty tag value is valid. The replacement has at most 10 tags and includes a SHA-256 request checksum.

Tagging is read/modify/write, not an atomic conditional update. Coordinate concurrent tag writers; an ETag condition on the object is not a tag-set compare-and-swap. The returned version ID is reused when available to target that data version. For unversioned objects or the mutable null version, coordinate object writers as well as tag writers. Requires the corresponding Get/Put/DeleteObjectTagging permissions and their version-specific variants when versionId is used. Tags are distinct from user metadata.

For general purpose S3 buckets, using regional HTTPS endpoints and AWS Signature Version 4. Directory buckets (S3 Express), access points, Outposts, and other AWS partitions need their own endpoint/authentication rules. Use a bucket name without dots for these virtual-hosted TLS examples; see the path-style example for dotted names.

Provide current IAM credentials in a private qa_data/aws/s3.json file with string fields access_key, secret_key, and session_token for temporary credentials. Prefer short-lived role credentials. This file is explicitly loaded; these examples do not discover profiles or refresh credentials. Keep it outside public content and source control. The session token is included in the signed request. TLS certificate verification is enabled on the Socket used by Rest.

Transport success and HTTP success are different. Keep full diagnostics private; signed requests and presigned URLs can contain credentials or grant access. For retryable reads use bounded backoff with jitter. Before retrying a write with an uncertain outcome, check the resource state. Keep keys, upload IDs, version IDs, ETags, and large sizes as strings.

AWS GetObjectTagging reference

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_TextCompare
oleobject loo_Credentials
long li_SameText1
long li_SameText2
string ls_Region
string ls_BucketName
oleobject loo_Endpoint
oleobject loo_Aws
oleobject loo_Rest
long li_SameText3
oleobject loo_Connection
oleobject loo_Xml
string ls_ObjectKey
oleobject loo_ObjectPath
long li_RestoredSlashes
string ls_Operation
string ls_TagKey
string ls_TagValue
long li_SameText4
long li_SameText5
long li_SameText6
long li_SameText7
string ls_ResponseBody
long li_SameText8
long li_SameText9
string ls_VersionId
long li_SameText10
long li_SameText11
long li_SameText12
long li_SameText13
oleobject loo_Replacement
oleobject loo_SeenKeys
long i
long li_Retained
long li_SameText14
string ls_ExistingKey
long li_SameText15
long li_SameText16
string ls_RequestBody
oleobject loo_Digest
string ls_ChecksumBase64
long li_SameText17

li_Success = 0

//  StringBuilder compares text by value in every generated language.
loo_TextCompare = create oleobject
li_rc = loo_TextCompare.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_TextCompare
    MessageBox("Error","Connecting to COM object failed")
    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 S3 operation.
loo_Credentials = create oleobject
li_rc = loo_Credentials.ConnectToNewObject("Chilkat.JsonObject")

loo_Credentials.Strict = 1
li_Success = loo_Credentials.LoadFile("qa_data/aws/s3.json")
if li_Success <> 1 then
    Write-Debug "Could not load private AWS credentials."
    destroy loo_TextCompare
    destroy loo_Credentials
    return
end if

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

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

//  General purpose bucket in the commercial AWS partition.
ls_Region = "us-west-2"
ls_BucketName = "amzn-s3-demo-bucket"
loo_Endpoint = create oleobject
li_rc = loo_Endpoint.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Endpoint.Append(ls_BucketName)
if li_Success <> 1 then
    Write-Debug "Could not build text."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    return
end if

li_Success = loo_Endpoint.Append(".")
if li_Success <> 1 then
    Write-Debug "Could not build text."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    return
end if

li_Success = loo_Endpoint.Append("s3.")
if li_Success <> 1 then
    Write-Debug "Could not build text."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    return
end if

li_Success = loo_Endpoint.Append(ls_Region)
if li_Success <> 1 then
    Write-Debug "Could not build text."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    return
end if

li_Success = loo_Endpoint.Append(".amazonaws.com")
if li_Success <> 1 then
    Write-Debug "Could not build text."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    return
end if

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 = "s3"
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_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    return
end if

//  Temporary credentials require this token in every signed query.
//  Keep request URLs private. Do not clear this parameter between requests.
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_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        return
    end if

    loo_TextCompare.Clear()
    loo_TextCompare.SetString(loo_Credentials.StringOf("session_token"))
    li_SameText3 = loo_TextCompare.ContentsEqual("",1)
    if li_SameText3 <> 1 then
        li_Success = loo_Rest.AddQueryParam("X-Amz-Security-Token",loo_Credentials.StringOf("session_token"))
        if li_Success <> 1 then
            Write-Debug "Could not prepare the request."
            destroy loo_TextCompare
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            return
        end if

    end if

end if

//  Connect to the SAME hostname used for TLS verification and request signing.
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_TextCompare
    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_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    return
end if

loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")

loo_Xml.Strict = 1
//  Supply an unencoded object key, not a URL. Preserve slashes in the key.
ls_ObjectKey = "documents/example.txt"
loo_ObjectPath = create oleobject
li_rc = loo_ObjectPath.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_ObjectPath.Append(ls_ObjectKey)
if li_Success <> 1 then
    Write-Debug "Could not build text."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    return
end if

li_Success = loo_ObjectPath.Encode("url_rfc3986","utf-8")
if li_Success <> 1 then
    Write-Debug "Could not encode the object key."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    return
end if

li_RestoredSlashes = loo_ObjectPath.Replace("%2F","/")
li_Success = loo_ObjectPath.Prepend("/")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    return
end if

ls_Operation = "merge"
ls_TagKey = "Environment"
ls_TagValue = "test"
loo_TextCompare.Clear()
loo_TextCompare.SetString(ls_Operation)
li_SameText4 = loo_TextCompare.ContentsEqual("read",1)
loo_TextCompare.Clear()
loo_TextCompare.SetString(ls_Operation)
li_SameText5 = loo_TextCompare.ContentsEqual("merge",1)
loo_TextCompare.Clear()
loo_TextCompare.SetString(ls_Operation)
li_SameText6 = loo_TextCompare.ContentsEqual("remove-one",1)
loo_TextCompare.Clear()
loo_TextCompare.SetString(ls_Operation)
li_SameText7 = loo_TextCompare.ContentsEqual("delete-all",1)
if (li_SameText4 <> 1) AND (li_SameText5 <> 1) AND (li_SameText6 <> 1) AND (li_SameText7 <> 1) then
    Write-Debug "Choose read, merge, remove-one, or delete-all."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    return
end if

li_Success = loo_Rest.AddQueryParam("tagging","")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    return
end if

ls_ResponseBody = loo_Rest.FullRequestNoBody("GET",loo_ObjectPath.GetAsString())
if loo_Rest.LastMethodSuccess <> 1 then
    Write-Debug "Request did not complete; inspect diagnostics privately."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    return
end if

if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug "S3 HTTP status: " + string(loo_Rest.ResponseStatusCode)
    li_Success = loo_Xml.LoadXml(ls_ResponseBody)
    loo_TextCompare.Clear()
    loo_TextCompare.SetString(loo_Xml.Tag)
    li_SameText8 = loo_TextCompare.ContentsEqual("Error",1)
    if (li_Success = 1) AND (li_SameText8 = 1) then
        Write-Debug "S3 error code: " + loo_Xml.GetChildContent("Code")
    end if

    //  Keep signed headers, credentials, URLs, and full diagnostics private.
    //  A timeout may leave a write's outcome uncertain. Check before retrying.
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    return
end if

li_Success = loo_Xml.LoadXml(ls_ResponseBody)
if li_Success <> 1 then
    Write-Debug "Expected well-formed XML."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    return
end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Xml.Tag)
li_SameText9 = loo_TextCompare.ContentsEqual("Tagging",1)
if li_SameText9 <> 1 then
    Write-Debug "Unexpected S3 response element; this is not a successful result."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    return
end if

if loo_Xml.HasChildWithTag("TagSet") <> 1 then
    Write-Debug "Missing TagSet."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    return
end if

//  Pin the version that was read when S3 returns its version ID.
ls_VersionId = loo_Rest.ResponseHdrByName("x-amz-version-id")
if loo_Rest.LastMethodSuccess <> 1 then
    ls_VersionId = ""
end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(ls_VersionId)
li_SameText10 = loo_TextCompare.ContentsEqual("",1)
if li_SameText10 <> 1 then
    li_Success = loo_Rest.AddQueryParam("versionId",ls_VersionId)
    if li_Success <> 1 then
        Write-Debug "Could not prepare the request."
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_ObjectPath
        return
    end if

end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(ls_Operation)
li_SameText11 = loo_TextCompare.ContentsEqual("read",1)
if li_SameText11 = 1 then
    Write-Debug loo_Xml.GetXml()
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    return
end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(ls_Operation)
li_SameText12 = loo_TextCompare.ContentsEqual("delete-all",1)
if li_SameText12 = 1 then
    ls_ResponseBody = loo_Rest.FullRequestNoBody("DELETE",loo_ObjectPath.GetAsString())
    if loo_Rest.LastMethodSuccess <> 1 then
        Write-Debug "Request did not complete; inspect diagnostics privately."
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_ObjectPath
        return
    end if

    if loo_Rest.ResponseStatusCode <> 204 then
        Write-Debug "S3 HTTP status: " + string(loo_Rest.ResponseStatusCode)
        li_Success = loo_Xml.LoadXml(ls_ResponseBody)
        loo_TextCompare.Clear()
        loo_TextCompare.SetString(loo_Xml.Tag)
        li_SameText13 = loo_TextCompare.ContentsEqual("Error",1)
        if (li_Success = 1) AND (li_SameText13 = 1) then
            Write-Debug "S3 error code: " + loo_Xml.GetChildContent("Code")
        end if

        //  Keep signed headers, credentials, URLs, and full diagnostics private.
        //  A timeout may leave a write's outcome uncertain. Check before retrying.
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_ObjectPath
        return
    end if

    Write-Debug "All object tags removed."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    return
end if

loo_Replacement = create oleobject
li_rc = loo_Replacement.ConnectToNewObject("Chilkat.Xml")

loo_Replacement.Tag = "Tagging"
li_Success = loo_Replacement.AddAttribute("xmlns","http://s3.amazonaws.com/doc/2006-03-01/")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    destroy loo_Replacement
    return
end if

loo_Replacement.NewChild2("TagSet","")
loo_SeenKeys = create oleobject
li_rc = loo_SeenKeys.ConnectToNewObject("Chilkat.Hashtable")

i = 0
li_Retained = 0
do while (i < loo_Xml.NumChildrenAt("TagSet"))
    loo_Xml.I = i
    loo_TextCompare.Clear()
    loo_TextCompare.SetString(loo_Xml.GetChildContent("TagSet|Tag[i]|Key"))
    li_SameText14 = loo_TextCompare.ContentsEqual("",1)
    if (loo_Xml.HasChildWithTag("TagSet|Tag[i]|Key") <> 1) OR (li_SameText14 = 1) then
        Write-Debug "Missing response field: TagSet|Tag[i]|Key"
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_ObjectPath
        destroy loo_Replacement
        destroy loo_SeenKeys
        return
    end if

    if loo_Xml.HasChildWithTag("TagSet|Tag[i]|Value") <> 1 then
        Write-Debug "Missing tag value."
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_ObjectPath
        destroy loo_Replacement
        destroy loo_SeenKeys
        return
    end if

    ls_ExistingKey = loo_Xml.GetChildContent("TagSet|Tag[i]|Key")
    if loo_SeenKeys.Contains(ls_ExistingKey) = 1 then
        Write-Debug "Duplicate key in returned tag set."
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_ObjectPath
        destroy loo_Replacement
        destroy loo_SeenKeys
        return
    end if

    li_Success = loo_SeenKeys.AddInt(ls_ExistingKey,1)
    if li_Success <> 1 then
        Write-Debug "Could not prepare the request."
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_ObjectPath
        destroy loo_Replacement
        destroy loo_SeenKeys
        return
    end if

    loo_TextCompare.Clear()
    loo_TextCompare.SetString(ls_ExistingKey)
    li_SameText15 = loo_TextCompare.ContentsEqual(ls_TagKey,1)
    if li_SameText15 <> 1 then
        loo_Replacement.I = li_Retained
        loo_Replacement.UpdateChildContent("TagSet|Tag[i]|Key",ls_ExistingKey)
        loo_Replacement.UpdateChildContent("TagSet|Tag[i]|Value",loo_Xml.GetChildContent("TagSet|Tag[i]|Value"))
        li_Retained = li_Retained + 1
    end if

    i = i + 1
loop
loo_TextCompare.Clear()
loo_TextCompare.SetString(ls_Operation)
li_SameText16 = loo_TextCompare.ContentsEqual("merge",1)
if li_SameText16 = 1 then
    loo_Replacement.I = li_Retained
    loo_Replacement.UpdateChildContent("TagSet|Tag[i]|Key",ls_TagKey)
    loo_Replacement.UpdateChildContent("TagSet|Tag[i]|Value",ls_TagValue)
    li_Retained = li_Retained + 1
end if

if li_Retained > 10 then
    Write-Debug "The resulting tag set exceeds 10 tags; no change was sent."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    destroy loo_Replacement
    destroy loo_SeenKeys
    return
end if

ls_RequestBody = loo_Replacement.GetXml()
loo_Digest = create oleobject
li_rc = loo_Digest.ConnectToNewObject("Chilkat.Crypt2")

loo_Digest.Charset = "utf-8"
loo_Digest.HashAlgorithm = "sha256"
loo_Digest.EncodingMode = "base64"
ls_ChecksumBase64 = loo_Digest.HashStringENC(ls_RequestBody)
if loo_Digest.LastMethodSuccess <> 1 then
    Write-Debug "Could not calculate the content checksum."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    destroy loo_Replacement
    destroy loo_SeenKeys
    destroy loo_Digest
    return
end if

li_Success = loo_Rest.AddHeader("x-amz-checksum-sha256",ls_ChecksumBase64)
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    destroy loo_Replacement
    destroy loo_SeenKeys
    destroy loo_Digest
    return
end if

li_Success = loo_Rest.AddHeader("Content-Type","application/xml")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    destroy loo_Replacement
    destroy loo_SeenKeys
    destroy loo_Digest
    return
end if

ls_ResponseBody = loo_Rest.FullRequestString("PUT",loo_ObjectPath.GetAsString(),ls_RequestBody)
if loo_Rest.LastMethodSuccess <> 1 then
    Write-Debug "Request did not complete; inspect diagnostics privately."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    destroy loo_Replacement
    destroy loo_SeenKeys
    destroy loo_Digest
    return
end if

if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug "S3 HTTP status: " + string(loo_Rest.ResponseStatusCode)
    li_Success = loo_Xml.LoadXml(ls_ResponseBody)
    loo_TextCompare.Clear()
    loo_TextCompare.SetString(loo_Xml.Tag)
    li_SameText17 = loo_TextCompare.ContentsEqual("Error",1)
    if (li_Success = 1) AND (li_SameText17 = 1) then
        Write-Debug "S3 error code: " + loo_Xml.GetChildContent("Code")
    end if

    //  Keep signed headers, credentials, URLs, and full diagnostics private.
    //  A timeout may leave a write's outcome uncertain. Check before retrying.
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_ObjectPath
    destroy loo_Replacement
    destroy loo_SeenKeys
    destroy loo_Digest
    return
end if

Write-Debug "Updated tag set saved; unrelated tags were preserved from the read."


destroy loo_TextCompare
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
destroy loo_Xml
destroy loo_ObjectPath
destroy loo_Replacement
destroy loo_SeenKeys
destroy loo_Digest