Amazon SNS: Filter a Subscription by JSON Message Body
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 MessageBody. 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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loStringCompare
LOCAL loCredentials
LOCAL lnStringMatch1
LOCAL lnStringMatch2
LOCAL lcRegion
LOCAL loEndpoint
LOCAL loAws
LOCAL loRest
LOCAL lnStringMatch3
LOCAL loXml
LOCAL lcValue
LOCAL lcResponseXml
LOCAL lcTopicArn
LOCAL loTopic
LOCAL loArnPrefix
LOCAL lcSubscriptionArn
LOCAL loSubscription
LOCAL loSubscriptionPrefix
LOCAL loFilter
LOCAL loConnection
LOCAL lnStringMatch4
LOCAL lnStringMatch5
LOCAL lnStringMatch6
LOCAL lnStringMatch7
LOCAL lnStringMatch8
LOCAL lnStringMatch9
LOCAL loAttributes
LOCAL lnMapIndex
LOCAL lnStringMatch10
LOCAL lcMapKey
lnSuccess = 0
loStringCompare = CreateObject('Chilkat.StringBuilder')
* Assumes Chilkat is unlocked. See Global Unlock Sample.
* Private credentials; do not put this file in public web content or source control.
loCredentials = CreateObject('Chilkat.JsonObject')
loCredentials.Strict = 1
lnSuccess = loCredentials.LoadFile("qa_data/aws/sns.json")
IF (lnSuccess <> 1) THEN
? "Could not load private SNS credentials."
RELEASE loStringCompare
RELEASE loCredentials
CANCEL
ENDIF
loStringCompare.SetString(loCredentials.StringOf("access_key"))
lnStringMatch1 = loStringCompare.ContentsEqual("",1)
IF ((loCredentials.JsonTypeOf("access_key") <> 1) OR (lnStringMatch1 = 1)) THEN
? "Missing or invalid access_key."
RELEASE loStringCompare
RELEASE loCredentials
CANCEL
ENDIF
loStringCompare.SetString(loCredentials.StringOf("secret_key"))
lnStringMatch2 = loStringCompare.ContentsEqual("",1)
IF ((loCredentials.JsonTypeOf("secret_key") <> 1) OR (lnStringMatch2 = 1)) THEN
? "Missing or invalid secret_key."
RELEASE loStringCompare
RELEASE loCredentials
CANCEL
ENDIF
lcRegion = "us-west-2"
loEndpoint = CreateObject('Chilkat.StringBuilder')
loEndpoint.Append("sns.")
loEndpoint.Append(lcRegion)
loEndpoint.Append(".amazonaws.com")
loAws = CreateObject('Chilkat.AuthAws')
loAws.AccessKey = loCredentials.StringOf("access_key")
loAws.SecretKey = loCredentials.StringOf("secret_key")
loAws.Region = lcRegion
loAws.ServiceName = "sns"
loAws.SignatureVersion = 4
loRest = CreateObject('Chilkat.Rest')
loRest.ConnectTimeoutMs = 20000
loRest.IdleTimeoutMs = 60000
loRest.VerboseLogging = 0
lnSuccess = loRest.SetAuthAws(loAws)
IF (lnSuccess <> 1) THEN
? "Could not configure AWS signing."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
CANCEL
ENDIF
IF (loCredentials.HasMember("session_token") = 1) THEN
loStringCompare.SetString(loCredentials.StringOf("session_token"))
lnStringMatch3 = loStringCompare.ContentsEqual("",1)
IF ((loCredentials.JsonTypeOf("session_token") <> 1) OR (lnStringMatch3 = 1)) THEN
? "session_token must be a nonempty string when supplied."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
CANCEL
ENDIF
ENDIF
loXml = CreateObject('Chilkat.Xml')
loXml.Strict = 1
lcTopicArn = "arn:aws:sns:us-west-2:123456789012:chilkat-standard-example"
loTopic = CreateObject('Chilkat.StringBuilder')
loTopic.Append(lcTopicArn)
loArnPrefix = CreateObject('Chilkat.StringBuilder')
loArnPrefix.Append("arn:aws:sns:")
loArnPrefix.Append(lcRegion)
loArnPrefix.Append(":")
IF (loTopic.StartsWith(loArnPrefix.GetAsString(),1) <> 1) THEN
? "Select an SNS topic ARN in the configured region and commercial AWS partition."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
CANCEL
ENDIF
* Replace with the confirmed subscription ARN, never "pending confirmation".
lcSubscriptionArn = "arn:aws:sns:us-west-2:123456789012:chilkat-standard-example:11111111-2222-3333-4444-555555555555"
loSubscription = CreateObject('Chilkat.StringBuilder')
loSubscription.Append(lcSubscriptionArn)
loSubscriptionPrefix = CreateObject('Chilkat.StringBuilder')
loSubscriptionPrefix.Append(lcTopicArn)
loSubscriptionPrefix.Append(":")
IF ((loSubscription.StartsWith(loSubscriptionPrefix.GetAsString(),1) <> 1) OR (loSubscription.Length <= loSubscriptionPrefix.Length)) THEN
? "Use a confirmed subscription ARN for the selected topic."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
CANCEL
ENDIF
loFilter = CreateObject('Chilkat.JsonObject')
loFilter.Strict = 1
lnSuccess = loFilter.Load('{"event":["order-created"],"amount":[{"numeric":[">=",100]}]}')
IF (lnSuccess <> 1) THEN
? "Could not construct JSON."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
CANCEL
ENDIF
* Explicit certificate verification; keep this Socket alive while Rest uses it.
loConnection = CreateObject('Chilkat.Socket')
loConnection.RequireSslCertVerify = 1
loConnection.MaxReadIdleMs = 60000
loConnection.MaxSendIdleMs = 60000
lnSuccess = loConnection.Connect(loEndpoint.GetAsString(),443,1,20000)
IF (lnSuccess <> 1) THEN
? "TLS connection failed; inspect diagnostics privately."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lnSuccess = loRest.UseConnection(loConnection,1)
IF (lnSuccess <> 1) THEN
? "Could not attach TLS connection."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lnSuccess = loRest.ClearAllQueryParams()
IF (lnSuccess <> 1) THEN
? "Could not clear parameters from the previous request."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
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.
lnSuccess = loRest.AddQueryParam("Action","SetSubscriptionAttributes")
IF (lnSuccess <> 1) THEN
? "Could not set Action."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lnSuccess = loRest.AddQueryParam("Version","2010-03-31")
IF (lnSuccess <> 1) THEN
? "Could not set Version."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
* Include temporary credentials in the signed form body on every request.
IF (loCredentials.HasMember("session_token") = 1) THEN
lnSuccess = loRest.AddQueryParam("X-Amz-Security-Token",loCredentials.StringOf("session_token"))
IF (lnSuccess <> 1) THEN
? "Could not set X-Amz-Security-Token."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
ENDIF
lnSuccess = loRest.AddQueryParam("SubscriptionArn",lcSubscriptionArn)
IF (lnSuccess <> 1) THEN
? "Could not set SubscriptionArn."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lnSuccess = loRest.AddQueryParam("AttributeName","FilterPolicyScope")
IF (lnSuccess <> 1) THEN
? "Could not set AttributeName."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lnSuccess = loRest.AddQueryParam("AttributeValue","MessageBody")
IF (lnSuccess <> 1) THEN
? "Could not set AttributeValue."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lcResponseXml = loRest.FullRequestFormUrlEncoded("POST","/")
IF (loRest.LastMethodSuccess <> 1) THEN
? "Request did not complete. Its outcome may be uncertain; reconcile before retrying."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lnSuccess = loXml.LoadXml(lcResponseXml)
IF (loRest.ResponseStatusCode <> 200) THEN
? "SNS HTTP status: " + STR(loRest.ResponseStatusCode)
IF (lnSuccess = 1) THEN
lcValue = loXml.GetChildContent("Error|Code")
IF (loXml.LastMethodSuccess = 1) THEN
? "AWS error code: " + lcValue
ENDIF
lcValue = loXml.GetChildContent("RequestId")
IF (loXml.LastMethodSuccess = 1) THEN
? "AWS request ID: " + lcValue
ENDIF
ENDIF
* Full messages, headers, and signing diagnostics may contain private data.
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
IF (lnSuccess <> 1) THEN
? "Expected a well-formed XML response."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
loStringCompare.SetString(loXml.Tag)
lnStringMatch4 = loStringCompare.ContentsEqual("SetSubscriptionAttributesResponse",1)
IF (lnStringMatch4 <> 1) THEN
? "Unexpected SNS response element."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lcValue = loXml.GetChildContent("ResponseMetadata|RequestId")
loStringCompare.SetString(lcValue)
lnStringMatch5 = loStringCompare.ContentsEqual("",1)
IF ((loXml.LastMethodSuccess <> 1) OR (lnStringMatch5 = 1)) THEN
? "Missing or empty ResponseMetadata|RequestId."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
? "AWS request ID: " + lcValue
lnSuccess = loRest.ClearAllQueryParams()
IF (lnSuccess <> 1) THEN
? "Could not clear parameters from the previous request."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
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.
lnSuccess = loRest.AddQueryParam("Action","SetSubscriptionAttributes")
IF (lnSuccess <> 1) THEN
? "Could not set Action."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lnSuccess = loRest.AddQueryParam("Version","2010-03-31")
IF (lnSuccess <> 1) THEN
? "Could not set Version."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
* Include temporary credentials in the signed form body on every request.
IF (loCredentials.HasMember("session_token") = 1) THEN
lnSuccess = loRest.AddQueryParam("X-Amz-Security-Token",loCredentials.StringOf("session_token"))
IF (lnSuccess <> 1) THEN
? "Could not set X-Amz-Security-Token."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
ENDIF
lnSuccess = loRest.AddQueryParam("SubscriptionArn",lcSubscriptionArn)
IF (lnSuccess <> 1) THEN
? "Could not set SubscriptionArn."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lnSuccess = loRest.AddQueryParam("AttributeName","FilterPolicy")
IF (lnSuccess <> 1) THEN
? "Could not set AttributeName."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lnSuccess = loRest.AddQueryParam("AttributeValue",loFilter.Emit())
IF (lnSuccess <> 1) THEN
? "Could not set AttributeValue."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lcResponseXml = loRest.FullRequestFormUrlEncoded("POST","/")
IF (loRest.LastMethodSuccess <> 1) THEN
? "Request did not complete. Its outcome may be uncertain; reconcile before retrying."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lnSuccess = loXml.LoadXml(lcResponseXml)
IF (loRest.ResponseStatusCode <> 200) THEN
? "SNS HTTP status: " + STR(loRest.ResponseStatusCode)
IF (lnSuccess = 1) THEN
lcValue = loXml.GetChildContent("Error|Code")
IF (loXml.LastMethodSuccess = 1) THEN
? "AWS error code: " + lcValue
ENDIF
lcValue = loXml.GetChildContent("RequestId")
IF (loXml.LastMethodSuccess = 1) THEN
? "AWS request ID: " + lcValue
ENDIF
ENDIF
* Full messages, headers, and signing diagnostics may contain private data.
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
IF (lnSuccess <> 1) THEN
? "Expected a well-formed XML response."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
loStringCompare.SetString(loXml.Tag)
lnStringMatch6 = loStringCompare.ContentsEqual("SetSubscriptionAttributesResponse",1)
IF (lnStringMatch6 <> 1) THEN
? "Unexpected SNS response element."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lcValue = loXml.GetChildContent("ResponseMetadata|RequestId")
loStringCompare.SetString(lcValue)
lnStringMatch7 = loStringCompare.ContentsEqual("",1)
IF ((loXml.LastMethodSuccess <> 1) OR (lnStringMatch7 = 1)) THEN
? "Missing or empty ResponseMetadata|RequestId."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
? "AWS request ID: " + lcValue
lnSuccess = loRest.ClearAllQueryParams()
IF (lnSuccess <> 1) THEN
? "Could not clear parameters from the previous request."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
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.
lnSuccess = loRest.AddQueryParam("Action","GetSubscriptionAttributes")
IF (lnSuccess <> 1) THEN
? "Could not set Action."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lnSuccess = loRest.AddQueryParam("Version","2010-03-31")
IF (lnSuccess <> 1) THEN
? "Could not set Version."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
* Include temporary credentials in the signed form body on every request.
IF (loCredentials.HasMember("session_token") = 1) THEN
lnSuccess = loRest.AddQueryParam("X-Amz-Security-Token",loCredentials.StringOf("session_token"))
IF (lnSuccess <> 1) THEN
? "Could not set X-Amz-Security-Token."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
ENDIF
lnSuccess = loRest.AddQueryParam("SubscriptionArn",lcSubscriptionArn)
IF (lnSuccess <> 1) THEN
? "Could not set SubscriptionArn."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lcResponseXml = loRest.FullRequestFormUrlEncoded("POST","/")
IF (loRest.LastMethodSuccess <> 1) THEN
? "Request did not complete. Inspect diagnostics privately."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lnSuccess = loXml.LoadXml(lcResponseXml)
IF (loRest.ResponseStatusCode <> 200) THEN
? "SNS HTTP status: " + STR(loRest.ResponseStatusCode)
IF (lnSuccess = 1) THEN
lcValue = loXml.GetChildContent("Error|Code")
IF (loXml.LastMethodSuccess = 1) THEN
? "AWS error code: " + lcValue
ENDIF
lcValue = loXml.GetChildContent("RequestId")
IF (loXml.LastMethodSuccess = 1) THEN
? "AWS request ID: " + lcValue
ENDIF
ENDIF
* Full messages, headers, and signing diagnostics may contain private data.
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
IF (lnSuccess <> 1) THEN
? "Expected a well-formed XML response."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
loStringCompare.SetString(loXml.Tag)
lnStringMatch8 = loStringCompare.ContentsEqual("GetSubscriptionAttributesResponse",1)
IF (lnStringMatch8 <> 1) THEN
? "Unexpected SNS response element."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
lcValue = loXml.GetChildContent("ResponseMetadata|RequestId")
loStringCompare.SetString(lcValue)
lnStringMatch9 = loStringCompare.ContentsEqual("",1)
IF ((loXml.LastMethodSuccess <> 1) OR (lnStringMatch9 = 1)) THEN
? "Missing or empty ResponseMetadata|RequestId."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
? "AWS request ID: " + lcValue
IF (loXml.HasChildWithTag("GetSubscriptionAttributesResult") <> 1) THEN
? "Missing result."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
CANCEL
ENDIF
loAttributes = CreateObject('Chilkat.JsonObject')
lnMapIndex = 0
DO WHILE (lnMapIndex < loXml.NumChildrenAt("GetSubscriptionAttributesResult|Attributes"))
loXml.I = lnMapIndex
lcValue = loXml.GetChildContent("GetSubscriptionAttributesResult|Attributes|entry[i]|key")
loStringCompare.SetString(lcValue)
lnStringMatch10 = loStringCompare.ContentsEqual("",1)
IF ((loXml.LastMethodSuccess <> 1) OR (lnStringMatch10 = 1)) THEN
? "Missing or empty GetSubscriptionAttributesResult|Attributes|entry[i]|key."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
RELEASE loAttributes
CANCEL
ENDIF
lcMapKey = lcValue
lcValue = loXml.GetChildContent("GetSubscriptionAttributesResult|Attributes|entry[i]|value")
IF (loXml.LastMethodSuccess <> 1) THEN
? "Missing map value."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
RELEASE loAttributes
CANCEL
ENDIF
lnSuccess = loAttributes.AppendString(lcMapKey,lcValue)
IF (lnSuccess <> 1) THEN
? "Invalid or duplicate map entry."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
RELEASE loAttributes
CANCEL
ENDIF
lnMapIndex = lnMapIndex + 1
ENDDO
? "FilterPolicyScope: " + loAttributes.StringOf("FilterPolicyScope")
? "FilterPolicy: " + loAttributes.StringOf("FilterPolicy")
? "Example completed."
RELEASE loStringCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loXml
RELEASE loTopic
RELEASE loArnPrefix
RELEASE loSubscription
RELEASE loSubscriptionPrefix
RELEASE loFilter
RELEASE loConnection
RELEASE loAttributes