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

Amazon SNS: Filter a Subscription by Message Attributes

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.

Configures event=order-created and amount >=100 using MessageAttributes. Attribute filtering needs a String event attribute and Number amount attribute; body filtering needs corresponding JSON properties. Scope and policy are separate writes, not an atomic change. Use a new/quiesced subscription during migration. Changes can take up to 15 minutes to propagate. Final readback reports stored configuration, not proof that propagation is complete.

Required IAM actions: sns:SetSubscriptionAttributes, sns:GetSubscriptionAttributes. Related SQS/KMS permissions are separate.

AWS references: SetSubscriptionAttributes GetSubscriptionAttributes

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_StringCompare
oleobject loo_Credentials
long li_StringMatch1
long li_StringMatch2
string ls_Region
oleobject loo_Endpoint
oleobject loo_Aws
oleobject loo_Rest
long li_StringMatch3
oleobject loo_Xml
string ls_Value
string ls_ResponseXml
string ls_TopicArn
oleobject loo_Topic
oleobject loo_ArnPrefix
string ls_SubscriptionArn
oleobject loo_Subscription
oleobject loo_SubscriptionPrefix
oleobject loo_Filter
oleobject loo_Connection
long li_StringMatch4
long li_StringMatch5
long li_StringMatch6
long li_StringMatch7
long li_StringMatch8
long li_StringMatch9
oleobject loo_Attributes
long li_MapIndex
long li_StringMatch10
string ls_MapKey

li_Success = 0

loo_StringCompare = create oleobject
li_rc = loo_StringCompare.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_StringCompare
    MessageBox("Error","Connecting to COM object failed")
    return
end if
//  Assumes Chilkat is unlocked. See Global Unlock Sample.
//  Private credentials; do not put this file in public web content or source control.
loo_Credentials = create oleobject
li_rc = loo_Credentials.ConnectToNewObject("Chilkat.JsonObject")

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

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

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

ls_Region = "us-west-2"
loo_Endpoint = create oleobject
li_rc = loo_Endpoint.ConnectToNewObject("Chilkat.StringBuilder")

loo_Endpoint.Append("sns.")
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 = "sns"
loo_Aws.SignatureVersion = 4
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")

loo_Rest.ConnectTimeoutMs = 20000
loo_Rest.IdleTimeoutMs = 60000
loo_Rest.VerboseLogging = 0
li_Success = loo_Rest.SetAuthAws(loo_Aws)
if li_Success <> 1 then
    Write-Debug "Could not configure AWS signing."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    return
end if

if loo_Credentials.HasMember("session_token") = 1 then
    loo_StringCompare.SetString(loo_Credentials.StringOf("session_token"))
    li_StringMatch3 = loo_StringCompare.ContentsEqual("",1)
    if (loo_Credentials.JsonTypeOf("session_token") <> 1) OR (li_StringMatch3 = 1) then
        Write-Debug "session_token must be a nonempty string when supplied."
        destroy loo_StringCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        return
    end if

end if

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

loo_Xml.Strict = 1

ls_TopicArn = "arn:aws:sns:us-west-2:123456789012:chilkat-standard-example"
loo_Topic = create oleobject
li_rc = loo_Topic.ConnectToNewObject("Chilkat.StringBuilder")

loo_Topic.Append(ls_TopicArn)
loo_ArnPrefix = create oleobject
li_rc = loo_ArnPrefix.ConnectToNewObject("Chilkat.StringBuilder")

loo_ArnPrefix.Append("arn:aws:sns:")
loo_ArnPrefix.Append(ls_Region)
loo_ArnPrefix.Append(":")
if loo_Topic.StartsWith(loo_ArnPrefix.GetAsString(),1) <> 1 then
    Write-Debug "Select an SNS topic ARN in the configured region and commercial AWS partition."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    return
end if

//  Replace with the confirmed subscription ARN, never "pending confirmation".
ls_SubscriptionArn = "arn:aws:sns:us-west-2:123456789012:chilkat-standard-example:11111111-2222-3333-4444-555555555555"
loo_Subscription = create oleobject
li_rc = loo_Subscription.ConnectToNewObject("Chilkat.StringBuilder")

loo_Subscription.Append(ls_SubscriptionArn)
loo_SubscriptionPrefix = create oleobject
li_rc = loo_SubscriptionPrefix.ConnectToNewObject("Chilkat.StringBuilder")

loo_SubscriptionPrefix.Append(ls_TopicArn)
loo_SubscriptionPrefix.Append(":")
if (loo_Subscription.StartsWith(loo_SubscriptionPrefix.GetAsString(),1) <> 1) OR (loo_Subscription.Length <= loo_SubscriptionPrefix.Length) then
    Write-Debug "Use a confirmed subscription ARN for the selected topic."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    return
end if

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

loo_Filter.Strict = 1
li_Success = loo_Filter.Load("{~"event~":[~"order-created~"],~"amount~":[{~"numeric~":[~">=~",100]}]}")
if li_Success <> 1 then
    Write-Debug "Could not construct JSON."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    return
end if

//  Explicit certificate verification; keep this Socket alive while Rest uses it.
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_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

li_Success = loo_Rest.UseConnection(loo_Connection,1)
if li_Success <> 1 then
    Write-Debug "Could not attach TLS connection."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

li_Success = loo_Rest.ClearAllQueryParams()
if li_Success <> 1 then
    Write-Debug "Could not clear parameters from the previous request."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

//  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.
li_Success = loo_Rest.AddQueryParam("Action","SetSubscriptionAttributes")
if li_Success <> 1 then
    Write-Debug "Could not set Action."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

li_Success = loo_Rest.AddQueryParam("Version","2010-03-31")
if li_Success <> 1 then
    Write-Debug "Could not set Version."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

//  Include temporary credentials in the signed form body on every request.
if loo_Credentials.HasMember("session_token") = 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 set X-Amz-Security-Token."
        destroy loo_StringCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Xml
        destroy loo_Topic
        destroy loo_ArnPrefix
        destroy loo_Subscription
        destroy loo_SubscriptionPrefix
        destroy loo_Filter
        destroy loo_Connection
        return
    end if

end if

li_Success = loo_Rest.AddQueryParam("SubscriptionArn",ls_SubscriptionArn)
if li_Success <> 1 then
    Write-Debug "Could not set SubscriptionArn."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

li_Success = loo_Rest.AddQueryParam("AttributeName","FilterPolicyScope")
if li_Success <> 1 then
    Write-Debug "Could not set AttributeName."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

li_Success = loo_Rest.AddQueryParam("AttributeValue","MessageAttributes")
if li_Success <> 1 then
    Write-Debug "Could not set AttributeValue."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

ls_ResponseXml = loo_Rest.FullRequestFormUrlEncoded("POST","/")
if loo_Rest.LastMethodSuccess <> 1 then
    Write-Debug "Request did not complete. Its outcome may be uncertain; reconcile before retrying."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

li_Success = loo_Xml.LoadXml(ls_ResponseXml)
if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug "SNS HTTP status: " + string(loo_Rest.ResponseStatusCode)
    if li_Success = 1 then
        ls_Value = loo_Xml.GetChildContent("Error|Code")
        if loo_Xml.LastMethodSuccess = 1 then
            Write-Debug "AWS error code: " + ls_Value
        end if

        ls_Value = loo_Xml.GetChildContent("RequestId")
        if loo_Xml.LastMethodSuccess = 1 then
            Write-Debug "AWS request ID: " + ls_Value
        end if

    end if

    //  Full messages, headers, and signing diagnostics may contain private data.
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

if li_Success <> 1 then
    Write-Debug "Expected a well-formed XML response."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

loo_StringCompare.SetString(loo_Xml.Tag)
li_StringMatch4 = loo_StringCompare.ContentsEqual("SetSubscriptionAttributesResponse",1)
if li_StringMatch4 <> 1 then
    Write-Debug "Unexpected SNS response element."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

ls_Value = loo_Xml.GetChildContent("ResponseMetadata|RequestId")
loo_StringCompare.SetString(ls_Value)
li_StringMatch5 = loo_StringCompare.ContentsEqual("",1)
if (loo_Xml.LastMethodSuccess <> 1) OR (li_StringMatch5 = 1) then
    Write-Debug "Missing or empty ResponseMetadata|RequestId."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

Write-Debug "AWS request ID: " + ls_Value
li_Success = loo_Rest.ClearAllQueryParams()
if li_Success <> 1 then
    Write-Debug "Could not clear parameters from the previous request."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

//  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.
li_Success = loo_Rest.AddQueryParam("Action","SetSubscriptionAttributes")
if li_Success <> 1 then
    Write-Debug "Could not set Action."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

li_Success = loo_Rest.AddQueryParam("Version","2010-03-31")
if li_Success <> 1 then
    Write-Debug "Could not set Version."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

//  Include temporary credentials in the signed form body on every request.
if loo_Credentials.HasMember("session_token") = 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 set X-Amz-Security-Token."
        destroy loo_StringCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Xml
        destroy loo_Topic
        destroy loo_ArnPrefix
        destroy loo_Subscription
        destroy loo_SubscriptionPrefix
        destroy loo_Filter
        destroy loo_Connection
        return
    end if

end if

li_Success = loo_Rest.AddQueryParam("SubscriptionArn",ls_SubscriptionArn)
if li_Success <> 1 then
    Write-Debug "Could not set SubscriptionArn."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

li_Success = loo_Rest.AddQueryParam("AttributeName","FilterPolicy")
if li_Success <> 1 then
    Write-Debug "Could not set AttributeName."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

li_Success = loo_Rest.AddQueryParam("AttributeValue",loo_Filter.Emit())
if li_Success <> 1 then
    Write-Debug "Could not set AttributeValue."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

ls_ResponseXml = loo_Rest.FullRequestFormUrlEncoded("POST","/")
if loo_Rest.LastMethodSuccess <> 1 then
    Write-Debug "Request did not complete. Its outcome may be uncertain; reconcile before retrying."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

li_Success = loo_Xml.LoadXml(ls_ResponseXml)
if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug "SNS HTTP status: " + string(loo_Rest.ResponseStatusCode)
    if li_Success = 1 then
        ls_Value = loo_Xml.GetChildContent("Error|Code")
        if loo_Xml.LastMethodSuccess = 1 then
            Write-Debug "AWS error code: " + ls_Value
        end if

        ls_Value = loo_Xml.GetChildContent("RequestId")
        if loo_Xml.LastMethodSuccess = 1 then
            Write-Debug "AWS request ID: " + ls_Value
        end if

    end if

    //  Full messages, headers, and signing diagnostics may contain private data.
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

if li_Success <> 1 then
    Write-Debug "Expected a well-formed XML response."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

loo_StringCompare.SetString(loo_Xml.Tag)
li_StringMatch6 = loo_StringCompare.ContentsEqual("SetSubscriptionAttributesResponse",1)
if li_StringMatch6 <> 1 then
    Write-Debug "Unexpected SNS response element."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

ls_Value = loo_Xml.GetChildContent("ResponseMetadata|RequestId")
loo_StringCompare.SetString(ls_Value)
li_StringMatch7 = loo_StringCompare.ContentsEqual("",1)
if (loo_Xml.LastMethodSuccess <> 1) OR (li_StringMatch7 = 1) then
    Write-Debug "Missing or empty ResponseMetadata|RequestId."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

Write-Debug "AWS request ID: " + ls_Value
li_Success = loo_Rest.ClearAllQueryParams()
if li_Success <> 1 then
    Write-Debug "Could not clear parameters from the previous request."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

//  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.
li_Success = loo_Rest.AddQueryParam("Action","GetSubscriptionAttributes")
if li_Success <> 1 then
    Write-Debug "Could not set Action."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

li_Success = loo_Rest.AddQueryParam("Version","2010-03-31")
if li_Success <> 1 then
    Write-Debug "Could not set Version."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

//  Include temporary credentials in the signed form body on every request.
if loo_Credentials.HasMember("session_token") = 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 set X-Amz-Security-Token."
        destroy loo_StringCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Xml
        destroy loo_Topic
        destroy loo_ArnPrefix
        destroy loo_Subscription
        destroy loo_SubscriptionPrefix
        destroy loo_Filter
        destroy loo_Connection
        return
    end if

end if

li_Success = loo_Rest.AddQueryParam("SubscriptionArn",ls_SubscriptionArn)
if li_Success <> 1 then
    Write-Debug "Could not set SubscriptionArn."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

ls_ResponseXml = loo_Rest.FullRequestFormUrlEncoded("POST","/")
if loo_Rest.LastMethodSuccess <> 1 then
    Write-Debug "Request did not complete. Inspect diagnostics privately."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

li_Success = loo_Xml.LoadXml(ls_ResponseXml)
if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug "SNS HTTP status: " + string(loo_Rest.ResponseStatusCode)
    if li_Success = 1 then
        ls_Value = loo_Xml.GetChildContent("Error|Code")
        if loo_Xml.LastMethodSuccess = 1 then
            Write-Debug "AWS error code: " + ls_Value
        end if

        ls_Value = loo_Xml.GetChildContent("RequestId")
        if loo_Xml.LastMethodSuccess = 1 then
            Write-Debug "AWS request ID: " + ls_Value
        end if

    end if

    //  Full messages, headers, and signing diagnostics may contain private data.
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

if li_Success <> 1 then
    Write-Debug "Expected a well-formed XML response."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

loo_StringCompare.SetString(loo_Xml.Tag)
li_StringMatch8 = loo_StringCompare.ContentsEqual("GetSubscriptionAttributesResponse",1)
if li_StringMatch8 <> 1 then
    Write-Debug "Unexpected SNS response element."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

ls_Value = loo_Xml.GetChildContent("ResponseMetadata|RequestId")
loo_StringCompare.SetString(ls_Value)
li_StringMatch9 = loo_StringCompare.ContentsEqual("",1)
if (loo_Xml.LastMethodSuccess <> 1) OR (li_StringMatch9 = 1) then
    Write-Debug "Missing or empty ResponseMetadata|RequestId."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

Write-Debug "AWS request ID: " + ls_Value
if loo_Xml.HasChildWithTag("GetSubscriptionAttributesResult") <> 1 then
    Write-Debug "Missing result."
    destroy loo_StringCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Xml
    destroy loo_Topic
    destroy loo_ArnPrefix
    destroy loo_Subscription
    destroy loo_SubscriptionPrefix
    destroy loo_Filter
    destroy loo_Connection
    return
end if

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

li_MapIndex = 0
do while (li_MapIndex < loo_Xml.NumChildrenAt("GetSubscriptionAttributesResult|Attributes"))
    loo_Xml.I = li_MapIndex
    ls_Value = loo_Xml.GetChildContent("GetSubscriptionAttributesResult|Attributes|entry[i]|key")
    loo_StringCompare.SetString(ls_Value)
    li_StringMatch10 = loo_StringCompare.ContentsEqual("",1)
    if (loo_Xml.LastMethodSuccess <> 1) OR (li_StringMatch10 = 1) then
        Write-Debug "Missing or empty GetSubscriptionAttributesResult|Attributes|entry[i]|key."
        destroy loo_StringCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Xml
        destroy loo_Topic
        destroy loo_ArnPrefix
        destroy loo_Subscription
        destroy loo_SubscriptionPrefix
        destroy loo_Filter
        destroy loo_Connection
        destroy loo_Attributes
        return
    end if

    ls_MapKey = ls_Value
    ls_Value = loo_Xml.GetChildContent("GetSubscriptionAttributesResult|Attributes|entry[i]|value")
    if loo_Xml.LastMethodSuccess <> 1 then
        Write-Debug "Missing map value."
        destroy loo_StringCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Xml
        destroy loo_Topic
        destroy loo_ArnPrefix
        destroy loo_Subscription
        destroy loo_SubscriptionPrefix
        destroy loo_Filter
        destroy loo_Connection
        destroy loo_Attributes
        return
    end if

    li_Success = loo_Attributes.AppendString(ls_MapKey,ls_Value)
    if li_Success <> 1 then
        Write-Debug "Invalid or duplicate map entry."
        destroy loo_StringCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Xml
        destroy loo_Topic
        destroy loo_ArnPrefix
        destroy loo_Subscription
        destroy loo_SubscriptionPrefix
        destroy loo_Filter
        destroy loo_Connection
        destroy loo_Attributes
        return
    end if

    li_MapIndex = li_MapIndex + 1
loop
Write-Debug "FilterPolicyScope: " + loo_Attributes.StringOf("FilterPolicyScope")
Write-Debug "FilterPolicy: " + loo_Attributes.StringOf("FilterPolicy")
Write-Debug "Example completed."


destroy loo_StringCompare
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Xml
destroy loo_Topic
destroy loo_ArnPrefix
destroy loo_Subscription
destroy loo_SubscriptionPrefix
destroy loo_Filter
destroy loo_Connection
destroy loo_Attributes