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

Amazon SQS: Configure a Dead-Letter Queue

See more Amazon SQS Examples

Configure two existing queues in the same region. queue_url identifies the source; dlq_url identifies the dead-letter queue. GetQueueAttributes obtains their actual ARNs, then the code checks that both are standard or both FIFO. It replaces the DLQ RedriveAllowPolicy with byQueue for this source and replaces the source RedrivePolicy with that DLQ and maxReceiveCount=5. The outer Attributes values contain serialized JSON strings, not nested objects.

These writes are not atomic. Inspect both policies after propagation and reconcile partial failure before retrying. Include other permitted sources if the DLQ is shared; replacing its allow policy can otherwise remove their permission. Choose receive count and retention for the workload; for standard queues, DLQ retention should exceed source retention. A FIFO DLQ can break strict end-to-end processing order. This configures future failed-message routing; it does not move existing DLQ messages back.

Uses SQS's AWS JSON protocol: POST to the regional root / with Content-Type: application/x-amz-json-1.0 and an operation-specific X-Amz-Target: AmazonSQS.... Chilkat.Rest and AuthAws sign with AWS Signature Version 4, service sqs. AWS still supports the older Query/XML protocol; these examples use JSON for simpler request and response handling. No AWS SDK is required.

Provide current IAM credentials in a private qa_data/aws/sqs.json with string fields access_key, secret_key, and session_token for temporary credentials. Queue-specific examples also read queue_url from this file. Set the region in the code to match the queue. These examples use commercial regional endpoints; other partitions or custom endpoints require corresponding changes. Prefer short-lived role credentials. The file is explicitly loaded; profiles and credential refresh are not automatic. Keep it outside public content and source control. The temporary token is included in the signed query; keep URLs and diagnostics private. TLS certificate verification is enabled.

Transport completion, HTTP status, and response validity are checked separately. Use bounded backoff with jitter for retryable errors, and refresh expired credentials. A timed-out write or receive may already have been accepted. Standard queues can deliver duplicates: make application processing idempotent and delete only after successful processing. Automatic reconnection is disabled for writes and receives to avoid replay after a lost response. Read-only queue listing permits reconnection.

Requires sqs:GetQueueAttributes and sqs:SetQueueAttributes on the relevant queues. Scope access to the intended queue. Customer-managed KMS encryption can require additional KMS permissions for producers and consumers.

AWS SetQueueAttributes reference

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoTextCompare
    Handle hoCredentials
    Boolean iSameText1
    Boolean iSameText2
    String sRegion
    Handle hoEndpoint
    String sQueueUrl
    Boolean iSameText3
    Handle hoExpectedPrefix
    Handle hoQueueText
    Variant vAws
    Handle hoAws
    Handle hoRest
    Boolean iSameText4
    Variant vConnection
    Handle hoConnection
    Handle hoBody
    Handle hoResult
    Variant vRequestBody
    Handle hoRequestBody
    Variant vResponseBody
    Handle hoResponseBody
    String sDlqUrl
    Boolean iSameText5
    Boolean iSameText6
    Handle hoDlqText
    Boolean iSameText7
    String sSourceArn
    Boolean iSameText8
    String sDlqArn
    Boolean iSameText9
    Handle hoSourceArnText
    Handle hoDlqArnText
    Boolean iSourceIsFifo
    Boolean iDlqIsFifo
    Handle hoAllowPolicy
    Handle hoRedrivePolicy
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    Move False To iSuccess

    //  StringBuilder compares text by value in every generated language.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoTextCompare
    If (Not(IsComObjectCreated(hoTextCompare))) Begin
        Send CreateComObject of hoTextCompare
    End
    //  Assumes Chilkat is unlocked. See Global Unlock Sample.
    Move False To iSuccess
    //  Private configuration, not a file in public web content or source control.
    //  Load current IAM credentials authorized for the SQS operation.
    Get Create (RefClass(cComChilkatJsonObject)) To hoCredentials
    If (Not(IsComObjectCreated(hoCredentials))) Begin
        Send CreateComObject of hoCredentials
    End
    Set ComStrict Of hoCredentials To True
    Get ComLoadFile Of hoCredentials "qa_data/aws/sqs.json" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not load private AWS credentials."
        Procedure_Return
    End

    Send ComClear To hoTextCompare
    Get ComStringOf Of hoCredentials "access_key" To sTemp1
    Get ComSetString Of hoTextCompare sTemp1 To iSuccess
    Get ComContentsEqual Of hoTextCompare "" True To iSameText1
    Get ComJsonTypeOf Of hoCredentials "access_key" To iTemp1
    If ((iTemp1 <> 1) Or (iSameText1 = True)) Begin
        Showln "Missing or invalid access_key."
        Procedure_Return
    End

    Send ComClear To hoTextCompare
    Get ComStringOf Of hoCredentials "secret_key" To sTemp1
    Get ComSetString Of hoTextCompare sTemp1 To iSuccess
    Get ComContentsEqual Of hoTextCompare "" True To iSameText2
    Get ComJsonTypeOf Of hoCredentials "secret_key" To iTemp1
    If ((iTemp1 <> 1) Or (iSameText2 = True)) Begin
        Showln "Missing or invalid secret_key."
        Procedure_Return
    End

    //  Set this once to the region containing the queue.
    Move "us-west-2" To sRegion
    Get Create (RefClass(cComChilkatStringBuilder)) To hoEndpoint
    If (Not(IsComObjectCreated(hoEndpoint))) Begin
        Send CreateComObject of hoEndpoint
    End
    Get ComAppend Of hoEndpoint "sqs." To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComAppend Of hoEndpoint sRegion To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComAppend Of hoEndpoint ".amazonaws.com" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    //  Use the exact QueueUrl returned by CreateQueue, GetQueueUrl, or ListQueues.
    //  This example targets a standard commercial regional endpoint, not a custom endpoint.
    Get ComStringOf Of hoCredentials "queue_url" To sQueueUrl
    Send ComClear To hoTextCompare
    Get ComSetString Of hoTextCompare sQueueUrl To iSuccess
    Get ComContentsEqual Of hoTextCompare "" True To iSameText3
    Get ComJsonTypeOf Of hoCredentials "queue_url" To iTemp1
    If ((iTemp1 <> 1) Or (iSameText3 = True)) Begin
        Showln "Missing or invalid queue_url in sqs.json."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoExpectedPrefix
    If (Not(IsComObjectCreated(hoExpectedPrefix))) Begin
        Send CreateComObject of hoExpectedPrefix
    End
    Get ComAppend Of hoExpectedPrefix "https://" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComGetAsString Of hoEndpoint To sTemp1
    Get ComAppend Of hoExpectedPrefix sTemp1 To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComAppend Of hoExpectedPrefix "/" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoQueueText
    If (Not(IsComObjectCreated(hoQueueText))) Begin
        Send CreateComObject of hoQueueText
    End
    Get ComAppend Of hoQueueText sQueueUrl To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComStartsWith Of hoQueueText (ComGetAsString(hoExpectedPrefix)) True To bTemp1
    If (bTemp1 <> True) Begin
        Showln "Queue URL must use HTTPS and the configured SQS region."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatAuthAws)) To hoAws
    If (Not(IsComObjectCreated(hoAws))) Begin
        Send CreateComObject of hoAws
    End
    Get ComStringOf Of hoCredentials "access_key" To sTemp1
    Set ComAccessKey Of hoAws To sTemp1
    Get ComStringOf Of hoCredentials "secret_key" To sTemp1
    Set ComSecretKey Of hoAws To sTemp1
    Set ComRegion Of hoAws To sRegion
    Set ComServiceName Of hoAws To "sqs"
    Set ComSignatureVersion Of hoAws To 4
    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End
    Set ComConnectTimeoutMs Of hoRest To 20000
    Set ComIdleTimeoutMs Of hoRest To 60000
    Get pvComObject of hoAws to vAws
    Get ComSetAuthAws Of hoRest vAws To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not configure AWS signing."
        Procedure_Return
    End

    //  Temporary IAM/STS credentials require their session token on every signed request.
    //  AddQueryParam includes it in SigV4's canonical query. Never log the request URL.
    //  Leave session_token absent or empty only for credentials that do not have one.
    Get ComHasMember Of hoCredentials "session_token" To bTemp1
    If (bTemp1 = True) Begin
        Get ComJsonTypeOf Of hoCredentials "session_token" To iTemp1
        If (iTemp1 <> 1) Begin
            Showln "session_token must be a string."
            Procedure_Return
        End

        Send ComClear To hoTextCompare
        Get ComStringOf Of hoCredentials "session_token" To sTemp1
        Get ComSetString Of hoTextCompare sTemp1 To iSuccess
        Get ComContentsEqual Of hoTextCompare "" True To iSameText4
        If (iSameText4 <> True) Begin
            Get ComStringOf Of hoCredentials "session_token" To sTemp1
            Get ComAddQueryParam Of hoRest "X-Amz-Security-Token" sTemp1 To iSuccess
            If (iSuccess <> True) Begin
                Showln "Could not set the session-token parameter."
                Procedure_Return
            End

        End

    End

    //  Supply a Socket to explicitly enable TLS certificate verification.
    Get Create (RefClass(cComChilkatSocket)) To hoConnection
    If (Not(IsComObjectCreated(hoConnection))) Begin
        Send CreateComObject of hoConnection
    End
    Set ComRequireSslCertVerify Of hoConnection To True
    Set ComMaxReadIdleMs Of hoConnection To 60000
    Set ComMaxSendIdleMs Of hoConnection To 60000
    Get ComGetAsString Of hoEndpoint To sTemp1
    Get ComConnect Of hoConnection sTemp1 443 True 20000 To iSuccess
    If (iSuccess <> True) Begin
        Showln "TLS connection failed; inspect diagnostics privately."
        Procedure_Return
    End

    //  Do not automatically reconnect/replay a write or receive after a lost response.
    Get pvComObject of hoConnection to vConnection
    Get ComUseConnection Of hoRest vConnection False To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not attach the TLS connection."
        Procedure_Return
    End

    Get ComAddHeader Of hoRest "Content-Type" "application/x-amz-json-1.0" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not set the content type."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoBody
    If (Not(IsComObjectCreated(hoBody))) Begin
        Send CreateComObject of hoBody
    End
    Get Create (RefClass(cComChilkatJsonObject)) To hoResult
    If (Not(IsComObjectCreated(hoResult))) Begin
        Send CreateComObject of hoResult
    End
    Set ComStrict Of hoResult To True
    Get Create (RefClass(cComChilkatStringBuilder)) To hoRequestBody
    If (Not(IsComObjectCreated(hoRequestBody))) Begin
        Send CreateComObject of hoRequestBody
    End
    Get Create (RefClass(cComChilkatStringBuilder)) To hoResponseBody
    If (Not(IsComObjectCreated(hoResponseBody))) Begin
        Send CreateComObject of hoResponseBody
    End
    Get ComAddHeader Of hoRest "X-Amz-Target" "AmazonSQS.GetQueueAttributes" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComUpdateString Of hoBody "QueueUrl" sQueueUrl To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComStringOf Of hoCredentials "dlq_url" To sDlqUrl
    Send ComClear To hoTextCompare
    Get ComSetString Of hoTextCompare sDlqUrl To iSuccess
    Get ComContentsEqual Of hoTextCompare "" True To iSameText5
    Get ComJsonTypeOf Of hoCredentials "dlq_url" To iTemp1
    If ((iTemp1 <> 1) Or (iSameText5 = True)) Begin
        Showln "Supply dlq_url in the private configuration."
        Procedure_Return
    End

    Send ComClear To hoTextCompare
    Get ComSetString Of hoTextCompare sDlqUrl To iSuccess
    Get ComContentsEqual Of hoTextCompare sQueueUrl True To iSameText6
    If (iSameText6 = True) Begin
        Showln "Source queue and dead-letter queue must differ."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoDlqText
    If (Not(IsComObjectCreated(hoDlqText))) Begin
        Send CreateComObject of hoDlqText
    End
    Get ComAppend Of hoDlqText sDlqUrl To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComStartsWith Of hoDlqText (ComGetAsString(hoExpectedPrefix)) True To bTemp1
    If (bTemp1 <> True) Begin
        Showln "DLQ URL must use the configured region."
        Procedure_Return
    End

    Get ComUpdateString Of hoBody "AttributeNames[0]" "QueueArn" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    //  EmitSb appends, so clear both builders before each request/page.
    Send ComClear To hoRequestBody
    Send ComClear To hoResponseBody
    Get pvComObject of hoRequestBody to vRequestBody
    Get ComEmitSb Of hoBody vRequestBody To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not serialize JSON."
        Procedure_Return
    End

    Get pvComObject of hoRequestBody to vRequestBody
    Get pvComObject of hoResponseBody to vResponseBody
    Get ComFullRequestSb Of hoRest "POST" "/" vRequestBody vResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Showln "Request did not complete; inspect diagnostics privately."
        //  A write or receive may have reached SQS. Do not blindly replay it.
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComResponseStatusCode Of hoRest To iTemp1
        Showln "SQS HTTP status: " iTemp1
        Get ComResponseHdrByName Of hoRest "x-amzn-RequestId" To sTemp1
        Showln "AWS request ID: " sTemp1
        Get pvComObject of hoResponseBody to vResponseBody
        Get ComLoadSb Of hoResult vResponseBody To iSuccess
        Get ComJsonTypeOf Of hoResult "__type" To iTemp1
        If ((iSuccess = True) And (iTemp1 = 1)) Begin
            Get ComStringOf Of hoResult "__type" To sTemp1
            Showln "AWS error type: " sTemp1
        End
        Else Begin
            Get ComResponseHdrByName Of hoRest "x-amzn-errortype" To sTemp1
            Showln "AWS error type: " sTemp1
        End

        //  Error messages, payloads, receipt handles and signed URLs can be private.
        //  HTTP 400 can be throttling, expired credentials, or invalid parameters.
        Procedure_Return
    End

    Get ComTrim Of hoResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not inspect response."
        Procedure_Return
    End

    Get ComStartsWith Of hoResponseBody "{" True To bTemp1
    If (bTemp1 <> True) Begin
        Showln "Expected a JSON object response."
        Procedure_Return
    End

    Get pvComObject of hoResponseBody to vResponseBody
    Get ComLoadSb Of hoResult vResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Showln "Expected well-formed JSON."
        Procedure_Return
    End

    Send ComClear To hoTextCompare
    Get ComStringOf Of hoResult "Attributes.QueueArn" To sTemp1
    Get ComSetString Of hoTextCompare sTemp1 To iSuccess
    Get ComContentsEqual Of hoTextCompare "" True To iSameText7
    Get ComJsonTypeOf Of hoResult "Attributes.QueueArn" To iTemp1
    If ((iTemp1 <> 1) Or (iSameText7 = True)) Begin
        Showln "Missing or invalid Attributes.QueueArn."
        Procedure_Return
    End

    Get ComStringOf Of hoResult "Attributes.QueueArn" To sSourceArn
    //  This is a distinct, deliberate next operation, not replay of a failed request.
    Get ComDisconnect Of hoRest 10 To iSuccess
    Get ComGetAsString Of hoEndpoint To sTemp1
    Get ComConnect Of hoConnection sTemp1 443 True 20000 To iSuccess
    If (iSuccess <> True) Begin
        Showln "TLS reconnection failed."
        Procedure_Return
    End

    Get pvComObject of hoConnection to vConnection
    Get ComUseConnection Of hoRest vConnection False To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not attach the TLS connection."
        Procedure_Return
    End

    Get ComAddHeader Of hoRest "X-Amz-Target" "AmazonSQS.GetQueueAttributes" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComLoad Of hoBody "{}" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComUpdateString Of hoBody "QueueUrl" sDlqUrl To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComUpdateString Of hoBody "AttributeNames[0]" "QueueArn" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    //  EmitSb appends, so clear both builders before each request/page.
    Send ComClear To hoRequestBody
    Send ComClear To hoResponseBody
    Get pvComObject of hoRequestBody to vRequestBody
    Get ComEmitSb Of hoBody vRequestBody To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not serialize JSON."
        Procedure_Return
    End

    Get pvComObject of hoRequestBody to vRequestBody
    Get pvComObject of hoResponseBody to vResponseBody
    Get ComFullRequestSb Of hoRest "POST" "/" vRequestBody vResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Showln "Request did not complete; inspect diagnostics privately."
        //  A write or receive may have reached SQS. Do not blindly replay it.
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComResponseStatusCode Of hoRest To iTemp1
        Showln "SQS HTTP status: " iTemp1
        Get ComResponseHdrByName Of hoRest "x-amzn-RequestId" To sTemp1
        Showln "AWS request ID: " sTemp1
        Get pvComObject of hoResponseBody to vResponseBody
        Get ComLoadSb Of hoResult vResponseBody To iSuccess
        Get ComJsonTypeOf Of hoResult "__type" To iTemp1
        If ((iSuccess = True) And (iTemp1 = 1)) Begin
            Get ComStringOf Of hoResult "__type" To sTemp1
            Showln "AWS error type: " sTemp1
        End
        Else Begin
            Get ComResponseHdrByName Of hoRest "x-amzn-errortype" To sTemp1
            Showln "AWS error type: " sTemp1
        End

        //  Error messages, payloads, receipt handles and signed URLs can be private.
        //  HTTP 400 can be throttling, expired credentials, or invalid parameters.
        Procedure_Return
    End

    Get ComTrim Of hoResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not inspect response."
        Procedure_Return
    End

    Get ComStartsWith Of hoResponseBody "{" True To bTemp1
    If (bTemp1 <> True) Begin
        Showln "Expected a JSON object response."
        Procedure_Return
    End

    Get pvComObject of hoResponseBody to vResponseBody
    Get ComLoadSb Of hoResult vResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Showln "Expected well-formed JSON."
        Procedure_Return
    End

    Send ComClear To hoTextCompare
    Get ComStringOf Of hoResult "Attributes.QueueArn" To sTemp1
    Get ComSetString Of hoTextCompare sTemp1 To iSuccess
    Get ComContentsEqual Of hoTextCompare "" True To iSameText8
    Get ComJsonTypeOf Of hoResult "Attributes.QueueArn" To iTemp1
    If ((iTemp1 <> 1) Or (iSameText8 = True)) Begin
        Showln "Missing or invalid Attributes.QueueArn."
        Procedure_Return
    End

    Get ComStringOf Of hoResult "Attributes.QueueArn" To sDlqArn
    Send ComClear To hoTextCompare
    Get ComSetString Of hoTextCompare sSourceArn To iSuccess
    Get ComContentsEqual Of hoTextCompare sDlqArn True To iSameText9
    If (iSameText9 = True) Begin
        Showln "Source and DLQ ARNs must differ."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSourceArnText
    If (Not(IsComObjectCreated(hoSourceArnText))) Begin
        Send CreateComObject of hoSourceArnText
    End
    Get Create (RefClass(cComChilkatStringBuilder)) To hoDlqArnText
    If (Not(IsComObjectCreated(hoDlqArnText))) Begin
        Send CreateComObject of hoDlqArnText
    End
    Get ComAppend Of hoSourceArnText sSourceArn To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComAppend Of hoDlqArnText sDlqArn To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComEndsWith Of hoSourceArnText ".fifo" True To iSourceIsFifo
    Get ComEndsWith Of hoDlqArnText ".fifo" True To iDlqIsFifo
    If (iSourceIsFifo <> iDlqIsFifo) Begin
        Showln "Source and DLQ must both be standard or both FIFO."
        Procedure_Return
    End

    //  Replace the DLQ allow policy with a policy permitting THIS source only.
    //  If other sources use this DLQ, include them too before applying the policy.
    Get Create (RefClass(cComChilkatJsonObject)) To hoAllowPolicy
    If (Not(IsComObjectCreated(hoAllowPolicy))) Begin
        Send CreateComObject of hoAllowPolicy
    End
    Get ComUpdateString Of hoAllowPolicy "redrivePermission" "byQueue" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComUpdateString Of hoAllowPolicy "sourceQueueArns[0]" sSourceArn To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    //  This is a distinct, deliberate next operation, not replay of a failed request.
    Get ComDisconnect Of hoRest 10 To iSuccess
    Get ComGetAsString Of hoEndpoint To sTemp1
    Get ComConnect Of hoConnection sTemp1 443 True 20000 To iSuccess
    If (iSuccess <> True) Begin
        Showln "TLS reconnection failed."
        Procedure_Return
    End

    Get pvComObject of hoConnection to vConnection
    Get ComUseConnection Of hoRest vConnection False To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not attach the TLS connection."
        Procedure_Return
    End

    Get ComAddHeader Of hoRest "X-Amz-Target" "AmazonSQS.SetQueueAttributes" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComLoad Of hoBody "{}" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComUpdateString Of hoBody "QueueUrl" sDlqUrl To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComEmit Of hoAllowPolicy To sTemp1
    Get ComUpdateString Of hoBody "Attributes.RedriveAllowPolicy" sTemp1 To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    //  EmitSb appends, so clear both builders before each request/page.
    Send ComClear To hoRequestBody
    Send ComClear To hoResponseBody
    Get pvComObject of hoRequestBody to vRequestBody
    Get ComEmitSb Of hoBody vRequestBody To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not serialize JSON."
        Procedure_Return
    End

    Get pvComObject of hoRequestBody to vRequestBody
    Get pvComObject of hoResponseBody to vResponseBody
    Get ComFullRequestSb Of hoRest "POST" "/" vRequestBody vResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Showln "Request did not complete; inspect diagnostics privately."
        //  A write or receive may have reached SQS. Do not blindly replay it.
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComResponseStatusCode Of hoRest To iTemp1
        Showln "SQS HTTP status: " iTemp1
        Get ComResponseHdrByName Of hoRest "x-amzn-RequestId" To sTemp1
        Showln "AWS request ID: " sTemp1
        Get pvComObject of hoResponseBody to vResponseBody
        Get ComLoadSb Of hoResult vResponseBody To iSuccess
        Get ComJsonTypeOf Of hoResult "__type" To iTemp1
        If ((iSuccess = True) And (iTemp1 = 1)) Begin
            Get ComStringOf Of hoResult "__type" To sTemp1
            Showln "AWS error type: " sTemp1
        End
        Else Begin
            Get ComResponseHdrByName Of hoRest "x-amzn-errortype" To sTemp1
            Showln "AWS error type: " sTemp1
        End

        //  Error messages, payloads, receipt handles and signed URLs can be private.
        //  HTTP 400 can be throttling, expired credentials, or invalid parameters.
        Procedure_Return
    End

    //  This operation normally returns an empty HTTP body on success.
    //  Also accept an empty JSON object; never require XML for this protocol.
    Get ComLength Of hoResponseBody To iTemp1
    If (iTemp1 > 0) Begin
        Get ComTrim Of hoResponseBody To iSuccess
        If (iSuccess <> True) Begin
            Showln "Could not inspect response."
            Procedure_Return
        End

        Get ComStartsWith Of hoResponseBody "{" True To bTemp1
        If (bTemp1 <> True) Begin
            Showln "Expected a JSON object response."
            Procedure_Return
        End

        Get pvComObject of hoResponseBody to vResponseBody
        Get ComLoadSb Of hoResult vResponseBody To iSuccess
        If (iSuccess <> True) Begin
            Showln "Expected well-formed JSON."
            Procedure_Return
        End

        Get ComSize Of hoResult To iTemp1
        If (iTemp1 <> 0) Begin
            Showln "Unexpected fields in the empty-result response."
            Procedure_Return
        End

    End

    Showln "DLQ allow-policy update accepted. The source policy has not been updated yet."
    Get Create (RefClass(cComChilkatJsonObject)) To hoRedrivePolicy
    If (Not(IsComObjectCreated(hoRedrivePolicy))) Begin
        Send CreateComObject of hoRedrivePolicy
    End
    Get ComUpdateString Of hoRedrivePolicy "deadLetterTargetArn" sDlqArn To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComUpdateInt Of hoRedrivePolicy "maxReceiveCount" 5 To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    //  This is a distinct, deliberate next operation, not replay of a failed request.
    Get ComDisconnect Of hoRest 10 To iSuccess
    Get ComGetAsString Of hoEndpoint To sTemp1
    Get ComConnect Of hoConnection sTemp1 443 True 20000 To iSuccess
    If (iSuccess <> True) Begin
        Showln "TLS reconnection failed."
        Procedure_Return
    End

    Get pvComObject of hoConnection to vConnection
    Get ComUseConnection Of hoRest vConnection False To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not attach the TLS connection."
        Procedure_Return
    End

    Get ComAddHeader Of hoRest "X-Amz-Target" "AmazonSQS.SetQueueAttributes" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComLoad Of hoBody "{}" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComUpdateString Of hoBody "QueueUrl" sQueueUrl To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    Get ComEmit Of hoRedrivePolicy To sTemp1
    Get ComUpdateString Of hoBody "Attributes.RedrivePolicy" sTemp1 To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not prepare the request."
        Procedure_Return
    End

    //  EmitSb appends, so clear both builders before each request/page.
    Send ComClear To hoRequestBody
    Send ComClear To hoResponseBody
    Get pvComObject of hoRequestBody to vRequestBody
    Get ComEmitSb Of hoBody vRequestBody To iSuccess
    If (iSuccess <> True) Begin
        Showln "Could not serialize JSON."
        Procedure_Return
    End

    Get pvComObject of hoRequestBody to vRequestBody
    Get pvComObject of hoResponseBody to vResponseBody
    Get ComFullRequestSb Of hoRest "POST" "/" vRequestBody vResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Showln "Request did not complete; inspect diagnostics privately."
        //  A write or receive may have reached SQS. Do not blindly replay it.
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComResponseStatusCode Of hoRest To iTemp1
        Showln "SQS HTTP status: " iTemp1
        Get ComResponseHdrByName Of hoRest "x-amzn-RequestId" To sTemp1
        Showln "AWS request ID: " sTemp1
        Get pvComObject of hoResponseBody to vResponseBody
        Get ComLoadSb Of hoResult vResponseBody To iSuccess
        Get ComJsonTypeOf Of hoResult "__type" To iTemp1
        If ((iSuccess = True) And (iTemp1 = 1)) Begin
            Get ComStringOf Of hoResult "__type" To sTemp1
            Showln "AWS error type: " sTemp1
        End
        Else Begin
            Get ComResponseHdrByName Of hoRest "x-amzn-errortype" To sTemp1
            Showln "AWS error type: " sTemp1
        End

        //  Error messages, payloads, receipt handles and signed URLs can be private.
        //  HTTP 400 can be throttling, expired credentials, or invalid parameters.
        Procedure_Return
    End

    //  This operation normally returns an empty HTTP body on success.
    //  Also accept an empty JSON object; never require XML for this protocol.
    Get ComLength Of hoResponseBody To iTemp1
    If (iTemp1 > 0) Begin
        Get ComTrim Of hoResponseBody To iSuccess
        If (iSuccess <> True) Begin
            Showln "Could not inspect response."
            Procedure_Return
        End

        Get ComStartsWith Of hoResponseBody "{" True To bTemp1
        If (bTemp1 <> True) Begin
            Showln "Expected a JSON object response."
            Procedure_Return
        End

        Get pvComObject of hoResponseBody to vResponseBody
        Get ComLoadSb Of hoResult vResponseBody To iSuccess
        If (iSuccess <> True) Begin
            Showln "Expected well-formed JSON."
            Procedure_Return
        End

        Get ComSize Of hoResult To iTemp1
        If (iTemp1 <> 0) Begin
            Showln "Unexpected fields in the empty-result response."
            Procedure_Return
        End

    End

    Showln "Source redrive-policy update accepted. Read both policies after propagation."
    //  These two writes are not a transaction. A later failure leaves the earlier change.


End_Procedure