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

Amazon SNS: List All Subscriptions for a Topic with Pagination

See more Amazon SNS Examples

Uses the current Amazon SNS Query API (Version=2010-03-31) through Chilkat.Rest and AuthAws, with HTTPS, Signature Version 4, and service sns. The API version date remains current. Action and input parameters are URL-encoded into a POST body, avoiding message text and recipient addresses in the URL. Set the actual region once; other AWS partitions need their documented endpoint suffix and ARN partition.

Load private qa_data/aws/sns.json with nonempty string fields access_key, secret_key, and session_token when using temporary credentials. Prefer short-lived role credentials. This sample does not discover profiles, obtain credentials, or refresh them automatically. The session token is included in the signed form body on every request. A Socket explicitly enables TLS certificate verification before passing the connection to Rest.

Checks setup calls, transport completion, HTTP status, XML parsing, result root, and required fields. Normal output includes identifiers, not full messages or headers. Keep detailed diagnostics private. For retryable failures, use bounded backoff with jitter in the application; these examples do not automatically retry writes. A Publish timeout can leave an accepted message and retrying a standard-topic/SMS publish can duplicate it. A returned MessageId confirms SNS acceptance, not subscriber or handset delivery.

Enumerates up to 100 subscriptions per response using opaque continuation tokens. The listing is not an atomic snapshot. SubscriptionArn can be a pending-confirmation marker; only a confirmed ARN is usable for subsequent management. Endpoint addresses are private; restrict this diagnostic output.

Required IAM actions: sns:ListSubscriptionsByTopic. Related SQS/KMS permissions are separate.

AWS references: ListSubscriptionsByTopic

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkAuthAws.pb"
IncludeFile "CkJsonObject.pb"
IncludeFile "CkSocket.pb"
IncludeFile "CkXml.pb"
IncludeFile "CkHashtable.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"

Procedure ChilkatExample()

    success.i = 0

    stringCompare.i = CkStringBuilder::ckCreate()
    If stringCompare.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  Assumes Chilkat is unlocked. See Global Unlock Sample.
    ;  Private credentials; do not put this file in public web content or source control.
    credentials.i = CkJsonObject::ckCreate()
    If credentials.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::setCkStrict(credentials, 1)
    success = CkJsonObject::ckLoadFile(credentials,"qa_data/aws/sns.json")
    If success <> 1
        Debug "Could not load private SNS credentials."
        CkStringBuilder::ckDispose(stringCompare)
        CkJsonObject::ckDispose(credentials)
        ProcedureReturn
    EndIf

    CkStringBuilder::ckSetString(stringCompare,CkJsonObject::ckStringOf(credentials,"access_key"))
    stringMatch1.i = CkStringBuilder::ckContentsEqual(stringCompare,"",1)
    If (CkJsonObject::ckJsonTypeOf(credentials,"access_key") <> 1) OR (stringMatch1 = 1)
        Debug "Missing or invalid access_key."
        CkStringBuilder::ckDispose(stringCompare)
        CkJsonObject::ckDispose(credentials)
        ProcedureReturn
    EndIf

    CkStringBuilder::ckSetString(stringCompare,CkJsonObject::ckStringOf(credentials,"secret_key"))
    stringMatch2.i = CkStringBuilder::ckContentsEqual(stringCompare,"",1)
    If (CkJsonObject::ckJsonTypeOf(credentials,"secret_key") <> 1) OR (stringMatch2 = 1)
        Debug "Missing or invalid secret_key."
        CkStringBuilder::ckDispose(stringCompare)
        CkJsonObject::ckDispose(credentials)
        ProcedureReturn
    EndIf

    region.s = "us-west-2"
    endpoint.i = CkStringBuilder::ckCreate()
    If endpoint.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkStringBuilder::ckAppend(endpoint,"sns.")
    CkStringBuilder::ckAppend(endpoint,region)
    CkStringBuilder::ckAppend(endpoint,".amazonaws.com")
    aws.i = CkAuthAws::ckCreate()
    If aws.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkAuthAws::setCkAccessKey(aws, CkJsonObject::ckStringOf(credentials,"access_key"))
    CkAuthAws::setCkSecretKey(aws, CkJsonObject::ckStringOf(credentials,"secret_key"))
    CkAuthAws::setCkRegion(aws, region)
    CkAuthAws::setCkServiceName(aws, "sns")
    CkAuthAws::setCkSignatureVersion(aws, 4)
    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkRest::setCkConnectTimeoutMs(rest, 20000)
    CkRest::setCkIdleTimeoutMs(rest, 60000)
    CkRest::setCkVerboseLogging(rest, 0)
    success = CkRest::ckSetAuthAws(rest,aws)
    If success <> 1
        Debug "Could not configure AWS signing."
        CkStringBuilder::ckDispose(stringCompare)
        CkJsonObject::ckDispose(credentials)
        CkStringBuilder::ckDispose(endpoint)
        CkAuthAws::ckDispose(aws)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    If CkJsonObject::ckHasMember(credentials,"session_token") = 1
        CkStringBuilder::ckSetString(stringCompare,CkJsonObject::ckStringOf(credentials,"session_token"))
        stringMatch3.i = CkStringBuilder::ckContentsEqual(stringCompare,"",1)
        If (CkJsonObject::ckJsonTypeOf(credentials,"session_token") <> 1) OR (stringMatch3 = 1)
            Debug "session_token must be a nonempty string when supplied."
            CkStringBuilder::ckDispose(stringCompare)
            CkJsonObject::ckDispose(credentials)
            CkStringBuilder::ckDispose(endpoint)
            CkAuthAws::ckDispose(aws)
            CkRest::ckDispose(rest)
            ProcedureReturn
        EndIf

    EndIf

    xml.i = CkXml::ckCreate()
    If xml.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkXml::setCkStrict(xml, 1)
    value.s
    responseXml.s
    topicArn.s = "arn:aws:sns:us-west-2:123456789012:chilkat-standard-example"
    topic.i = CkStringBuilder::ckCreate()
    If topic.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkStringBuilder::ckAppend(topic,topicArn)
    arnPrefix.i = CkStringBuilder::ckCreate()
    If arnPrefix.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkStringBuilder::ckAppend(arnPrefix,"arn:aws:sns:")
    CkStringBuilder::ckAppend(arnPrefix,region)
    CkStringBuilder::ckAppend(arnPrefix,":")
    If CkStringBuilder::ckStartsWith(topic,CkStringBuilder::ckGetAsString(arnPrefix),1) <> 1
        Debug "Select an SNS topic ARN in the configured region and commercial AWS partition."
        CkStringBuilder::ckDispose(stringCompare)
        CkJsonObject::ckDispose(credentials)
        CkStringBuilder::ckDispose(endpoint)
        CkAuthAws::ckDispose(aws)
        CkRest::ckDispose(rest)
        CkXml::ckDispose(xml)
        CkStringBuilder::ckDispose(topic)
        CkStringBuilder::ckDispose(arnPrefix)
        ProcedureReturn
    EndIf

    ;  Explicit certificate verification; keep this Socket alive while Rest uses it.
    connection.i = CkSocket::ckCreate()
    If connection.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkSocket::setCkRequireSslCertVerify(connection, 1)
    CkSocket::setCkMaxReadIdleMs(connection, 60000)
    CkSocket::setCkMaxSendIdleMs(connection, 60000)
    success = CkSocket::ckConnect(connection,CkStringBuilder::ckGetAsString(endpoint),443,1,20000)
    If success <> 1
        Debug "TLS connection failed; inspect diagnostics privately."
        CkStringBuilder::ckDispose(stringCompare)
        CkJsonObject::ckDispose(credentials)
        CkStringBuilder::ckDispose(endpoint)
        CkAuthAws::ckDispose(aws)
        CkRest::ckDispose(rest)
        CkXml::ckDispose(xml)
        CkStringBuilder::ckDispose(topic)
        CkStringBuilder::ckDispose(arnPrefix)
        CkSocket::ckDispose(connection)
        ProcedureReturn
    EndIf

    success = CkRest::ckUseConnection(rest,connection,1)
    If success <> 1
        Debug "Could not attach TLS connection."
        CkStringBuilder::ckDispose(stringCompare)
        CkJsonObject::ckDispose(credentials)
        CkStringBuilder::ckDispose(endpoint)
        CkAuthAws::ckDispose(aws)
        CkRest::ckDispose(rest)
        CkXml::ckDispose(xml)
        CkStringBuilder::ckDispose(topic)
        CkStringBuilder::ckDispose(arnPrefix)
        CkSocket::ckDispose(connection)
        ProcedureReturn
    EndIf

    seenTokens.i = CkHashtable::ckCreate()
    If seenTokens.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    nextToken.s = ""
    more.i = 1
    page.i = 0
    While (more = 1)
        If page = 10000
            Debug "Page bound reached; enumeration incomplete."
            CkStringBuilder::ckDispose(stringCompare)
            CkJsonObject::ckDispose(credentials)
            CkStringBuilder::ckDispose(endpoint)
            CkAuthAws::ckDispose(aws)
            CkRest::ckDispose(rest)
            CkXml::ckDispose(xml)
            CkStringBuilder::ckDispose(topic)
            CkStringBuilder::ckDispose(arnPrefix)
            CkSocket::ckDispose(connection)
            CkHashtable::ckDispose(seenTokens)
            ProcedureReturn
        EndIf

        page = page + 1
        success = CkRest::ckClearAllQueryParams(rest)
        If success <> 1
            Debug "Could not clear parameters from the previous request."
            CkStringBuilder::ckDispose(stringCompare)
            CkJsonObject::ckDispose(credentials)
            CkStringBuilder::ckDispose(endpoint)
            CkAuthAws::ckDispose(aws)
            CkRest::ckDispose(rest)
            CkXml::ckDispose(xml)
            CkStringBuilder::ckDispose(topic)
            CkStringBuilder::ckDispose(arnPrefix)
            CkSocket::ckDispose(connection)
            CkHashtable::ckDispose(seenTokens)
            ProcedureReturn
        EndIf

        ;  Build a fresh form for each request; do not retain parameters from a previous action.
        ;  AddQueryParam encodes raw values into the POST body. Do not pre-encode them.
        success = CkRest::ckAddQueryParam(rest,"Action","ListSubscriptionsByTopic")
        If success <> 1
            Debug "Could not set Action."
            CkStringBuilder::ckDispose(stringCompare)
            CkJsonObject::ckDispose(credentials)
            CkStringBuilder::ckDispose(endpoint)
            CkAuthAws::ckDispose(aws)
            CkRest::ckDispose(rest)
            CkXml::ckDispose(xml)
            CkStringBuilder::ckDispose(topic)
            CkStringBuilder::ckDispose(arnPrefix)
            CkSocket::ckDispose(connection)
            CkHashtable::ckDispose(seenTokens)
            ProcedureReturn
        EndIf

        success = CkRest::ckAddQueryParam(rest,"Version","2010-03-31")
        If success <> 1
            Debug "Could not set Version."
            CkStringBuilder::ckDispose(stringCompare)
            CkJsonObject::ckDispose(credentials)
            CkStringBuilder::ckDispose(endpoint)
            CkAuthAws::ckDispose(aws)
            CkRest::ckDispose(rest)
            CkXml::ckDispose(xml)
            CkStringBuilder::ckDispose(topic)
            CkStringBuilder::ckDispose(arnPrefix)
            CkSocket::ckDispose(connection)
            CkHashtable::ckDispose(seenTokens)
            ProcedureReturn
        EndIf

        ;  Include temporary credentials in the signed form body on every request.
        If CkJsonObject::ckHasMember(credentials,"session_token") = 1
            success = CkRest::ckAddQueryParam(rest,"X-Amz-Security-Token",CkJsonObject::ckStringOf(credentials,"session_token"))
            If success <> 1
                Debug "Could not set X-Amz-Security-Token."
                CkStringBuilder::ckDispose(stringCompare)
                CkJsonObject::ckDispose(credentials)
                CkStringBuilder::ckDispose(endpoint)
                CkAuthAws::ckDispose(aws)
                CkRest::ckDispose(rest)
                CkXml::ckDispose(xml)
                CkStringBuilder::ckDispose(topic)
                CkStringBuilder::ckDispose(arnPrefix)
                CkSocket::ckDispose(connection)
                CkHashtable::ckDispose(seenTokens)
                ProcedureReturn
            EndIf

        EndIf

        success = CkRest::ckAddQueryParam(rest,"TopicArn",topicArn)
        If success <> 1
            Debug "Could not set TopicArn."
            CkStringBuilder::ckDispose(stringCompare)
            CkJsonObject::ckDispose(credentials)
            CkStringBuilder::ckDispose(endpoint)
            CkAuthAws::ckDispose(aws)
            CkRest::ckDispose(rest)
            CkXml::ckDispose(xml)
            CkStringBuilder::ckDispose(topic)
            CkStringBuilder::ckDispose(arnPrefix)
            CkSocket::ckDispose(connection)
            CkHashtable::ckDispose(seenTokens)
            ProcedureReturn
        EndIf

        CkStringBuilder::ckSetString(stringCompare,nextToken)
        stringMatch4.i = CkStringBuilder::ckContentsEqual(stringCompare,"",1)
        If stringMatch4 <> 1
            success = CkRest::ckAddQueryParam(rest,"NextToken",nextToken)
            If success <> 1
                Debug "Could not set NextToken."
                CkStringBuilder::ckDispose(stringCompare)
                CkJsonObject::ckDispose(credentials)
                CkStringBuilder::ckDispose(endpoint)
                CkAuthAws::ckDispose(aws)
                CkRest::ckDispose(rest)
                CkXml::ckDispose(xml)
                CkStringBuilder::ckDispose(topic)
                CkStringBuilder::ckDispose(arnPrefix)
                CkSocket::ckDispose(connection)
                CkHashtable::ckDispose(seenTokens)
                ProcedureReturn
            EndIf

        EndIf

        responseXml = CkRest::ckFullRequestFormUrlEncoded(rest,"POST","/")
        If CkRest::ckLastMethodSuccess(rest) <> 1
            Debug "Request did not complete. Inspect diagnostics privately."
            CkStringBuilder::ckDispose(stringCompare)
            CkJsonObject::ckDispose(credentials)
            CkStringBuilder::ckDispose(endpoint)
            CkAuthAws::ckDispose(aws)
            CkRest::ckDispose(rest)
            CkXml::ckDispose(xml)
            CkStringBuilder::ckDispose(topic)
            CkStringBuilder::ckDispose(arnPrefix)
            CkSocket::ckDispose(connection)
            CkHashtable::ckDispose(seenTokens)
            ProcedureReturn
        EndIf

        success = CkXml::ckLoadXml(xml,responseXml)
        If CkRest::ckResponseStatusCode(rest) <> 200
            Debug "SNS HTTP status: " + Str(CkRest::ckResponseStatusCode(rest))
            If success = 1
                value = CkXml::ckGetChildContent(xml,"Error|Code")
                If CkXml::ckLastMethodSuccess(xml) = 1
                    Debug "AWS error code: " + value
                EndIf

                value = CkXml::ckGetChildContent(xml,"RequestId")
                If CkXml::ckLastMethodSuccess(xml) = 1
                    Debug "AWS request ID: " + value
                EndIf

            EndIf

            ;  Full messages, headers, and signing diagnostics may contain private data.
            CkStringBuilder::ckDispose(stringCompare)
            CkJsonObject::ckDispose(credentials)
            CkStringBuilder::ckDispose(endpoint)
            CkAuthAws::ckDispose(aws)
            CkRest::ckDispose(rest)
            CkXml::ckDispose(xml)
            CkStringBuilder::ckDispose(topic)
            CkStringBuilder::ckDispose(arnPrefix)
            CkSocket::ckDispose(connection)
            CkHashtable::ckDispose(seenTokens)
            ProcedureReturn
        EndIf

        If success <> 1
            Debug "Expected a well-formed XML response."
            CkStringBuilder::ckDispose(stringCompare)
            CkJsonObject::ckDispose(credentials)
            CkStringBuilder::ckDispose(endpoint)
            CkAuthAws::ckDispose(aws)
            CkRest::ckDispose(rest)
            CkXml::ckDispose(xml)
            CkStringBuilder::ckDispose(topic)
            CkStringBuilder::ckDispose(arnPrefix)
            CkSocket::ckDispose(connection)
            CkHashtable::ckDispose(seenTokens)
            ProcedureReturn
        EndIf

        CkStringBuilder::ckSetString(stringCompare,CkXml::ckTag(xml))
        stringMatch5.i = CkStringBuilder::ckContentsEqual(stringCompare,"ListSubscriptionsByTopicResponse",1)
        If stringMatch5 <> 1
            Debug "Unexpected SNS response element."
            CkStringBuilder::ckDispose(stringCompare)
            CkJsonObject::ckDispose(credentials)
            CkStringBuilder::ckDispose(endpoint)
            CkAuthAws::ckDispose(aws)
            CkRest::ckDispose(rest)
            CkXml::ckDispose(xml)
            CkStringBuilder::ckDispose(topic)
            CkStringBuilder::ckDispose(arnPrefix)
            CkSocket::ckDispose(connection)
            CkHashtable::ckDispose(seenTokens)
            ProcedureReturn
        EndIf

        value = CkXml::ckGetChildContent(xml,"ResponseMetadata|RequestId")
        CkStringBuilder::ckSetString(stringCompare,value)
        stringMatch6.i = CkStringBuilder::ckContentsEqual(stringCompare,"",1)
        If (CkXml::ckLastMethodSuccess(xml) <> 1) OR (stringMatch6 = 1)
            Debug "Missing or empty ResponseMetadata|RequestId."
            CkStringBuilder::ckDispose(stringCompare)
            CkJsonObject::ckDispose(credentials)
            CkStringBuilder::ckDispose(endpoint)
            CkAuthAws::ckDispose(aws)
            CkRest::ckDispose(rest)
            CkXml::ckDispose(xml)
            CkStringBuilder::ckDispose(topic)
            CkStringBuilder::ckDispose(arnPrefix)
            CkSocket::ckDispose(connection)
            CkHashtable::ckDispose(seenTokens)
            ProcedureReturn
        EndIf

        Debug "AWS request ID: " + value
        If CkXml::ckHasChildWithTag(xml,"ListSubscriptionsByTopicResult") <> 1
            Debug "Missing result."
            CkStringBuilder::ckDispose(stringCompare)
            CkJsonObject::ckDispose(credentials)
            CkStringBuilder::ckDispose(endpoint)
            CkAuthAws::ckDispose(aws)
            CkRest::ckDispose(rest)
            CkXml::ckDispose(xml)
            CkStringBuilder::ckDispose(topic)
            CkStringBuilder::ckDispose(arnPrefix)
            CkSocket::ckDispose(connection)
            CkHashtable::ckDispose(seenTokens)
            ProcedureReturn
        EndIf

        itemIndex.i = 0
        While (itemIndex < CkXml::ckNumChildrenAt(xml,"ListSubscriptionsByTopicResult|Subscriptions"))
            CkXml::setCkI(xml, itemIndex)
            value = CkXml::ckGetChildContent(xml,"ListSubscriptionsByTopicResult|Subscriptions|member[i]|SubscriptionArn")
            CkStringBuilder::ckSetString(stringCompare,value)
            stringMatch7.i = CkStringBuilder::ckContentsEqual(stringCompare,"",1)
            If (CkXml::ckLastMethodSuccess(xml) <> 1) OR (stringMatch7 = 1)
                Debug "Missing or empty ListSubscriptionsByTopicResult|Subscriptions|member[i]|SubscriptionArn."
                CkStringBuilder::ckDispose(stringCompare)
                CkJsonObject::ckDispose(credentials)
                CkStringBuilder::ckDispose(endpoint)
                CkAuthAws::ckDispose(aws)
                CkRest::ckDispose(rest)
                CkXml::ckDispose(xml)
                CkStringBuilder::ckDispose(topic)
                CkStringBuilder::ckDispose(arnPrefix)
                CkSocket::ckDispose(connection)
                CkHashtable::ckDispose(seenTokens)
                ProcedureReturn
            EndIf

            Debug "SubscriptionArn: " + value
            value = CkXml::ckGetChildContent(xml,"ListSubscriptionsByTopicResult|Subscriptions|member[i]|TopicArn")
            CkStringBuilder::ckSetString(stringCompare,value)
            stringMatch8.i = CkStringBuilder::ckContentsEqual(stringCompare,"",1)
            If (CkXml::ckLastMethodSuccess(xml) <> 1) OR (stringMatch8 = 1)
                Debug "Missing or empty ListSubscriptionsByTopicResult|Subscriptions|member[i]|TopicArn."
                CkStringBuilder::ckDispose(stringCompare)
                CkJsonObject::ckDispose(credentials)
                CkStringBuilder::ckDispose(endpoint)
                CkAuthAws::ckDispose(aws)
                CkRest::ckDispose(rest)
                CkXml::ckDispose(xml)
                CkStringBuilder::ckDispose(topic)
                CkStringBuilder::ckDispose(arnPrefix)
                CkSocket::ckDispose(connection)
                CkHashtable::ckDispose(seenTokens)
                ProcedureReturn
            EndIf

            Debug "TopicArn: " + value
            value = CkXml::ckGetChildContent(xml,"ListSubscriptionsByTopicResult|Subscriptions|member[i]|Protocol")
            CkStringBuilder::ckSetString(stringCompare,value)
            stringMatch9.i = CkStringBuilder::ckContentsEqual(stringCompare,"",1)
            If (CkXml::ckLastMethodSuccess(xml) <> 1) OR (stringMatch9 = 1)
                Debug "Missing or empty ListSubscriptionsByTopicResult|Subscriptions|member[i]|Protocol."
                CkStringBuilder::ckDispose(stringCompare)
                CkJsonObject::ckDispose(credentials)
                CkStringBuilder::ckDispose(endpoint)
                CkAuthAws::ckDispose(aws)
                CkRest::ckDispose(rest)
                CkXml::ckDispose(xml)
                CkStringBuilder::ckDispose(topic)
                CkStringBuilder::ckDispose(arnPrefix)
                CkSocket::ckDispose(connection)
                CkHashtable::ckDispose(seenTokens)
                ProcedureReturn
            EndIf

            Debug "Protocol: " + value
            value = CkXml::ckGetChildContent(xml,"ListSubscriptionsByTopicResult|Subscriptions|member[i]|Endpoint")
            CkStringBuilder::ckSetString(stringCompare,value)
            stringMatch10.i = CkStringBuilder::ckContentsEqual(stringCompare,"",1)
            If (CkXml::ckLastMethodSuccess(xml) <> 1) OR (stringMatch10 = 1)
                Debug "Missing or empty ListSubscriptionsByTopicResult|Subscriptions|member[i]|Endpoint."
                CkStringBuilder::ckDispose(stringCompare)
                CkJsonObject::ckDispose(credentials)
                CkStringBuilder::ckDispose(endpoint)
                CkAuthAws::ckDispose(aws)
                CkRest::ckDispose(rest)
                CkXml::ckDispose(xml)
                CkStringBuilder::ckDispose(topic)
                CkStringBuilder::ckDispose(arnPrefix)
                CkSocket::ckDispose(connection)
                CkHashtable::ckDispose(seenTokens)
                ProcedureReturn
            EndIf

            Debug "Endpoint: " + value
            itemIndex = itemIndex + 1
        Wend
        nextToken = CkXml::ckGetChildContent(xml,"ListSubscriptionsByTopicResult|NextToken")
        If CkXml::ckLastMethodSuccess(xml) <> 1
            nextToken = ""
        EndIf

        more = 0
        CkStringBuilder::ckSetString(stringCompare,nextToken)
        stringMatch11.i = CkStringBuilder::ckContentsEqual(stringCompare,"",1)
        If stringMatch11 <> 1
            If CkHashtable::ckContains(seenTokens,nextToken) = 1
                Debug "Repeated pagination token; enumeration incomplete."
                CkStringBuilder::ckDispose(stringCompare)
                CkJsonObject::ckDispose(credentials)
                CkStringBuilder::ckDispose(endpoint)
                CkAuthAws::ckDispose(aws)
                CkRest::ckDispose(rest)
                CkXml::ckDispose(xml)
                CkStringBuilder::ckDispose(topic)
                CkStringBuilder::ckDispose(arnPrefix)
                CkSocket::ckDispose(connection)
                CkHashtable::ckDispose(seenTokens)
                ProcedureReturn
            EndIf

            success = CkHashtable::ckAddStr(seenTokens,nextToken,"seen")
            If success <> 1
                Debug "Could not track pagination."
                CkStringBuilder::ckDispose(stringCompare)
                CkJsonObject::ckDispose(credentials)
                CkStringBuilder::ckDispose(endpoint)
                CkAuthAws::ckDispose(aws)
                CkRest::ckDispose(rest)
                CkXml::ckDispose(xml)
                CkStringBuilder::ckDispose(topic)
                CkStringBuilder::ckDispose(arnPrefix)
                CkSocket::ckDispose(connection)
                CkHashtable::ckDispose(seenTokens)
                ProcedureReturn
            EndIf

            more = 1
        EndIf

    Wend
    Debug "Example completed."


    CkStringBuilder::ckDispose(stringCompare)
    CkJsonObject::ckDispose(credentials)
    CkStringBuilder::ckDispose(endpoint)
    CkAuthAws::ckDispose(aws)
    CkRest::ckDispose(rest)
    CkXml::ckDispose(xml)
    CkStringBuilder::ckDispose(topic)
    CkStringBuilder::ckDispose(arnPrefix)
    CkSocket::ckDispose(connection)
    CkHashtable::ckDispose(seenTokens)


    ProcedureReturn
EndProcedure