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

Amazon SNS: Subscribe an SMS Phone Number to a Standard Topic

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.

Subscribes an endpoint to a standard topic. The sample explicitly requests ReturnSubscriptionArn=false and distinguishes the literal pending confirmation from a returned ARN. Email recipients must follow the confirmation workflow; an accepted Subscribe request does not prove confirmation or delivery. Do not bypass endpoint-owner confirmation. Email/SMS are not FIFO-topic subscription protocols.

Use an authorized E.164 phone number. This creates a topic subscription; a direct SMS Publish does not need it. Sandbox verification, origination/registration requirements, opt-outs and spending restrictions still apply. A subscription ARN alone is not a handset-delivery guarantee. See SMS sandbox requirements.

Required IAM action: sns:Subscribe. Grant only the intended resource access; direct SMS does not have a topic ARN resource. Topic policies and KMS key access can also affect requests.

AWS Subscribe reference

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @iTmp1 int
    DECLARE @iTmp2 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    DECLARE @stringCompare int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @stringCompare OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    --  Assumes Chilkat is unlocked. See Global Unlock Sample.
    --  Private credentials; do not put this file in public web content or source control.
    DECLARE @credentials int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @credentials OUT

    EXEC sp_OASetProperty @credentials, 'Strict', 1
    EXEC sp_OAMethod @credentials, 'LoadFile', @success OUT, 'qa_data/aws/sns.json'
    IF @success <> 1
      BEGIN

        PRINT 'Could not load private SNS credentials.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        RETURN
      END
    EXEC sp_OAMethod @credentials, 'StringOf', @sTmp0 OUT, 'access_key'
    EXEC sp_OAMethod @stringCompare, 'SetString', @success OUT, @sTmp0
    DECLARE @stringMatch1 int
    EXEC sp_OAMethod @stringCompare, 'ContentsEqual', @stringMatch1 OUT, '', 1
    EXEC sp_OAMethod @credentials, 'JsonTypeOf', @iTmp0 OUT, 'access_key'
    IF (@iTmp0 <> 1) or (@stringMatch1 = 1)
      BEGIN

        PRINT 'Missing or invalid access_key.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        RETURN
      END
    EXEC sp_OAMethod @credentials, 'StringOf', @sTmp0 OUT, 'secret_key'
    EXEC sp_OAMethod @stringCompare, 'SetString', @success OUT, @sTmp0
    DECLARE @stringMatch2 int
    EXEC sp_OAMethod @stringCompare, 'ContentsEqual', @stringMatch2 OUT, '', 1
    EXEC sp_OAMethod @credentials, 'JsonTypeOf', @iTmp0 OUT, 'secret_key'
    IF (@iTmp0 <> 1) or (@stringMatch2 = 1)
      BEGIN

        PRINT 'Missing or invalid secret_key.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        RETURN
      END
    DECLARE @region nvarchar(4000)
    SELECT @region = 'us-west-2'
    DECLARE @endpoint int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @endpoint OUT

    EXEC sp_OAMethod @endpoint, 'Append', @success OUT, 'sns.'
    EXEC sp_OAMethod @endpoint, 'Append', @success OUT, @region
    EXEC sp_OAMethod @endpoint, 'Append', @success OUT, '.amazonaws.com'
    DECLARE @aws int
    EXEC @hr = sp_OACreate 'Chilkat.AuthAws', @aws OUT

    EXEC sp_OAMethod @credentials, 'StringOf', @sTmp0 OUT, 'access_key'
    EXEC sp_OASetProperty @aws, 'AccessKey', @sTmp0
    EXEC sp_OAMethod @credentials, 'StringOf', @sTmp0 OUT, 'secret_key'
    EXEC sp_OASetProperty @aws, 'SecretKey', @sTmp0
    EXEC sp_OASetProperty @aws, 'Region', @region
    EXEC sp_OASetProperty @aws, 'ServiceName', 'sns'
    EXEC sp_OASetProperty @aws, 'SignatureVersion', 4
    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat.Rest', @rest OUT

    EXEC sp_OASetProperty @rest, 'ConnectTimeoutMs', 20000
    EXEC sp_OASetProperty @rest, 'IdleTimeoutMs', 60000
    EXEC sp_OASetProperty @rest, 'VerboseLogging', 0
    EXEC sp_OAMethod @rest, 'SetAuthAws', @success OUT, @aws
    IF @success <> 1
      BEGIN

        PRINT 'Could not configure AWS signing.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        RETURN
      END
    EXEC sp_OAMethod @credentials, 'HasMember', @iTmp0 OUT, 'session_token'
    IF @iTmp0 = 1
      BEGIN
        EXEC sp_OAMethod @credentials, 'StringOf', @sTmp0 OUT, 'session_token'
        EXEC sp_OAMethod @stringCompare, 'SetString', @success OUT, @sTmp0
        DECLARE @stringMatch3 int
        EXEC sp_OAMethod @stringCompare, 'ContentsEqual', @stringMatch3 OUT, '', 1
        EXEC sp_OAMethod @credentials, 'JsonTypeOf', @iTmp0 OUT, 'session_token'
        IF (@iTmp0 <> 1) or (@stringMatch3 = 1)
          BEGIN

            PRINT 'session_token must be a nonempty string when supplied.'
            EXEC @hr = sp_OADestroy @stringCompare
            EXEC @hr = sp_OADestroy @credentials
            EXEC @hr = sp_OADestroy @endpoint
            EXEC @hr = sp_OADestroy @aws
            EXEC @hr = sp_OADestroy @rest
            RETURN
          END
      END
    DECLARE @xml int
    EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml OUT

    EXEC sp_OASetProperty @xml, 'Strict', 1
    DECLARE @value nvarchar(4000)

    DECLARE @topicArn nvarchar(4000)
    SELECT @topicArn = 'arn:aws:sns:us-west-2:123456789012:chilkat-standard-example'
    DECLARE @topic int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @topic OUT

    EXEC sp_OAMethod @topic, 'Append', @success OUT, @topicArn
    DECLARE @arnPrefix int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @arnPrefix OUT

    EXEC sp_OAMethod @arnPrefix, 'Append', @success OUT, 'arn:aws:sns:'
    EXEC sp_OAMethod @arnPrefix, 'Append', @success OUT, @region
    EXEC sp_OAMethod @arnPrefix, 'Append', @success OUT, ':'
    EXEC sp_OAMethod @arnPrefix, 'GetAsString', @sTmp0 OUT
    EXEC sp_OAMethod @topic, 'StartsWith', @iTmp0 OUT, @sTmp0, 1
    IF @iTmp0 <> 1
      BEGIN

        PRINT 'Select an SNS topic ARN in the configured region and commercial AWS partition.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        RETURN
      END
    EXEC sp_OAMethod @topic, 'EndsWith', @iTmp0 OUT, '.fifo', 1
    IF @iTmp0 = 1
      BEGIN

        PRINT 'This example uses a standard topic. FIFO publishing needs group/deduplication handling.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        RETURN
      END
    --  Use an authorized recipient in E.164 format; this number is a placeholder.
    DECLARE @phoneNumber nvarchar(4000)
    SELECT @phoneNumber = '+15551234567'
    DECLARE @phone int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @phone OUT

    EXEC sp_OAMethod @phone, 'Append', @success OUT, @phoneNumber
    EXEC sp_OAMethod @phone, 'GetRange', @sTmp0 OUT, 1, 1, 0
    EXEC sp_OAMethod @stringCompare, 'SetString', @success OUT, @sTmp0
    DECLARE @stringMatch4 int
    EXEC sp_OAMethod @stringCompare, 'ContentsEqual', @stringMatch4 OUT, '0', 1
    EXEC sp_OAMethod @phone, 'StartsWith', @iTmp0 OUT, '+', 1
    EXEC sp_OAGetProperty @phone, 'Length', @iTmp1 OUT
    EXEC sp_OAGetProperty @phone, 'Length', @iTmp2 OUT
    IF (@iTmp0 <> 1) or (@iTmp1 < 2) or (@iTmp2 > 16) or (@stringMatch4 = 1)
      BEGIN

        PRINT 'Use E.164: + followed by at most 15 digits, starting with a nonzero digit.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        RETURN
      END
    DECLARE @digits int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @digits OUT

    EXEC sp_OAMethod @digits, 'Append', @success OUT, '0123456789'
    DECLARE @position int
    SELECT @position = 1
    EXEC sp_OAGetProperty @phone, 'Length', @iTmp0 OUT
    WHILE (@position < @iTmp0)
      BEGIN
        EXEC sp_OAMethod @phone, 'GetRange', @sTmp0 OUT, @position, 1, 0
        EXEC sp_OAMethod @digits, 'Contains', @iTmp0 OUT, @sTmp0, 1
        IF @iTmp0 <> 1
          BEGIN

            PRINT 'Phone number must contain only + and digits.'
            EXEC @hr = sp_OADestroy @stringCompare
            EXEC @hr = sp_OADestroy @credentials
            EXEC @hr = sp_OADestroy @endpoint
            EXEC @hr = sp_OADestroy @aws
            EXEC @hr = sp_OADestroy @rest
            EXEC @hr = sp_OADestroy @xml
            EXEC @hr = sp_OADestroy @topic
            EXEC @hr = sp_OADestroy @arnPrefix
            EXEC @hr = sp_OADestroy @phone
            EXEC @hr = sp_OADestroy @digits
            RETURN
          END
        SELECT @position = @position + 1
      END
    --  Explicit certificate verification; keep this Socket alive while Rest uses it.
    DECLARE @connection int
    EXEC @hr = sp_OACreate 'Chilkat.Socket', @connection OUT

    EXEC sp_OASetProperty @connection, 'RequireSslCertVerify', 1
    EXEC sp_OASetProperty @connection, 'MaxReadIdleMs', 60000
    EXEC sp_OASetProperty @connection, 'MaxSendIdleMs', 60000
    EXEC sp_OAMethod @endpoint, 'GetAsString', @sTmp0 OUT
    EXEC sp_OAMethod @connection, 'Connect', @success OUT, @sTmp0, 443, 1, 20000
    IF @success <> 1
      BEGIN

        PRINT 'TLS connection failed; inspect diagnostics privately.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    EXEC sp_OAMethod @rest, 'UseConnection', @success OUT, @connection, 1
    IF @success <> 1
      BEGIN

        PRINT 'Could not attach TLS connection.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    EXEC sp_OAMethod @rest, 'ClearAllQueryParams', @success OUT
    IF @success <> 1
      BEGIN

        PRINT 'Could not clear parameters from the previous request.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    --  Build a fresh form for each request; do not retain previous parameters.
    --  AddQueryParam encodes raw values into the POST body. Do not pre-encode them.
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'Action', 'Subscribe'
    IF @success <> 1
      BEGIN

        PRINT 'Could not set Action.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'Version', '2010-03-31'
    IF @success <> 1
      BEGIN

        PRINT 'Could not set Version.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    --  Include temporary credentials in the signed form body on every request.
    EXEC sp_OAMethod @credentials, 'HasMember', @iTmp0 OUT, 'session_token'
    IF @iTmp0 = 1
      BEGIN
        EXEC sp_OAMethod @credentials, 'StringOf', @sTmp0 OUT, 'session_token'
        EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'X-Amz-Security-Token', @sTmp0
        IF @success <> 1
          BEGIN

            PRINT 'Could not set X-Amz-Security-Token.'
            EXEC @hr = sp_OADestroy @stringCompare
            EXEC @hr = sp_OADestroy @credentials
            EXEC @hr = sp_OADestroy @endpoint
            EXEC @hr = sp_OADestroy @aws
            EXEC @hr = sp_OADestroy @rest
            EXEC @hr = sp_OADestroy @xml
            EXEC @hr = sp_OADestroy @topic
            EXEC @hr = sp_OADestroy @arnPrefix
            EXEC @hr = sp_OADestroy @phone
            EXEC @hr = sp_OADestroy @digits
            EXEC @hr = sp_OADestroy @connection
            RETURN
          END
      END
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'TopicArn', @topicArn
    IF @success <> 1
      BEGIN

        PRINT 'Could not set TopicArn.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'Protocol', 'sms'
    IF @success <> 1
      BEGIN

        PRINT 'Could not set Protocol.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'Endpoint', @phoneNumber
    IF @success <> 1
      BEGIN

        PRINT 'Could not set Endpoint.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'ReturnSubscriptionArn', 'false'
    IF @success <> 1
      BEGIN

        PRINT 'Could not set ReturnSubscriptionArn.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    DECLARE @responseXml nvarchar(4000)
    EXEC sp_OAMethod @rest, 'FullRequestFormUrlEncoded', @responseXml OUT, 'POST', '/'
    EXEC sp_OAGetProperty @rest, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 <> 1
      BEGIN

        PRINT 'Request did not complete. Its outcome may be uncertain; reconcile before retrying.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    EXEC sp_OAMethod @xml, 'LoadXml', @success OUT, @responseXml
    EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
    IF @iTmp0 <> 200
      BEGIN

        EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
        PRINT 'SNS HTTP status: ' + @iTmp0
        IF @success = 1
          BEGIN
            EXEC sp_OAMethod @xml, 'GetChildContent', @value OUT, 'Error|Code'
            EXEC sp_OAGetProperty @xml, 'LastMethodSuccess', @iTmp0 OUT
            IF @iTmp0 = 1
              BEGIN

                PRINT 'AWS error code: ' + @value
              END
            EXEC sp_OAMethod @xml, 'GetChildContent', @value OUT, 'RequestId'
            EXEC sp_OAGetProperty @xml, 'LastMethodSuccess', @iTmp0 OUT
            IF @iTmp0 = 1
              BEGIN

                PRINT 'AWS request ID: ' + @value
              END
          END
        --  Full messages, headers, and signing diagnostics may contain private data.
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    IF @success <> 1
      BEGIN

        PRINT 'Expected a well-formed XML response.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    EXEC sp_OAGetProperty @xml, 'Tag', @sTmp0 OUT
    EXEC sp_OAMethod @stringCompare, 'SetString', @success OUT, @sTmp0
    DECLARE @stringMatch5 int
    EXEC sp_OAMethod @stringCompare, 'ContentsEqual', @stringMatch5 OUT, 'SubscribeResponse', 1
    IF @stringMatch5 <> 1
      BEGIN

        PRINT 'Unexpected SNS response element.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    EXEC sp_OAMethod @xml, 'GetChildContent', @value OUT, 'ResponseMetadata|RequestId'
    EXEC sp_OAMethod @stringCompare, 'SetString', @success OUT, @value
    DECLARE @stringMatch6 int
    EXEC sp_OAMethod @stringCompare, 'ContentsEqual', @stringMatch6 OUT, '', 1
    EXEC sp_OAGetProperty @xml, 'LastMethodSuccess', @iTmp0 OUT
    IF (@iTmp0 <> 1) or (@stringMatch6 = 1)
      BEGIN

        PRINT 'Missing or empty ResponseMetadata|RequestId.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END

    PRINT 'AWS request ID: ' + @value
    EXEC sp_OAMethod @xml, 'GetChildContent', @value OUT, 'SubscribeResult|SubscriptionArn'
    EXEC sp_OAMethod @stringCompare, 'SetString', @success OUT, @value
    DECLARE @stringMatch7 int
    EXEC sp_OAMethod @stringCompare, 'ContentsEqual', @stringMatch7 OUT, '', 1
    EXEC sp_OAGetProperty @xml, 'LastMethodSuccess', @iTmp0 OUT
    IF (@iTmp0 <> 1) or (@stringMatch7 = 1)
      BEGIN

        PRINT 'Missing or empty SubscribeResult|SubscriptionArn.'
        EXEC @hr = sp_OADestroy @stringCompare
        EXEC @hr = sp_OADestroy @credentials
        EXEC @hr = sp_OADestroy @endpoint
        EXEC @hr = sp_OADestroy @aws
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        EXEC @hr = sp_OADestroy @topic
        EXEC @hr = sp_OADestroy @arnPrefix
        EXEC @hr = sp_OADestroy @phone
        EXEC @hr = sp_OADestroy @digits
        EXEC @hr = sp_OADestroy @connection
        RETURN
      END
    EXEC sp_OAMethod @stringCompare, 'SetString', @success OUT, @value
    DECLARE @stringMatch8 int
    EXEC sp_OAMethod @stringCompare, 'ContentsEqual', @stringMatch8 OUT, 'pending confirmation', 1
    IF @stringMatch8 = 1
      BEGIN

        PRINT 'Subscription is pending confirmation; delivery is not active yet.'
      END
    ELSE
      BEGIN

        PRINT 'Subscription ARN: ' + @value

        PRINT 'Subscription request succeeded.'
      END

    EXEC @hr = sp_OADestroy @stringCompare
    EXEC @hr = sp_OADestroy @credentials
    EXEC @hr = sp_OADestroy @endpoint
    EXEC @hr = sp_OADestroy @aws
    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @xml
    EXEC @hr = sp_OADestroy @topic
    EXEC @hr = sp_OADestroy @arnPrefix
    EXEC @hr = sp_OADestroy @phone
    EXEC @hr = sp_OADestroy @digits
    EXEC @hr = sp_OADestroy @connection


END
GO