bin/middleware.js
function subscribe(topicArn) {

        // validate the topic arn
        if (!rxTopicArn.test(topicArn)) throw Error('Cannot subscribe to an invalid AWS Topic Arn: ' + topicArn);

        // if already subscribed then return now
        if (subscriptions[topicArn]) return subscriptions[topicArn].promise;

        // create and store the deferred promise
        const deferred = defer();
        subscriptions[topicArn] = deferred;

        // make the sns subscribe request
        const params = {
            Protocol: /^(https?):/.exec(config.endpoint)[1],
            TopicArn: topicArn,
            Endpoint: config.endpoint
        };
        config.sns.subscribe(params, function(err) {
            debug('Subscription request for ' + topicArn + (err ? ' failed : ' + err.message : ' sent.'));
            if (err) return deferred.reject(err);
        });

        return deferred.promise;
    }
function subscribe(topicArn) {

        // validate the topic arn
        if (!rxTopicArn.test(topicArn)) throw Error('Cannot subscribe to an invalid AWS Topic Arn: ' + topicArn);

        // if already subscribed then return now
        if (subscriptions[topicArn]) return subscriptions[topicArn].promise;

        // create and store the deferred promise
        const deferred = defer();
        subscriptions[topicArn] = deferred;

        // make the sns subscribe request
        const params = {
            Protocol: /^(https?):/.exec(config.endpoint)[1],
            TopicArn: topicArn,
            Endpoint: config.endpoint
        };
        config.sns.subscribe(params, function(err) {
            debug('Subscription request for ' + topicArn + (err ? ' failed : ' + err.message : ' sent.'));
            if (err) return deferred.reject(err);
        });

        return deferred.promise;
    }
function subscribe ( topicArn ) { // validate the topic arn if ( ! rxTopicArn . test ( topicArn ) ) throw Error ( 'Cannot subscribe to an invalid AWS Topic Arn: ' + topicArn ) ; // if already subscribed then return now if ( subscriptions [ topicArn ] ) return subscriptions [ topicArn ] . promise ; // create and store the deferred promise const deferred = defer ( ) ; subscriptions [ topicArn ] = deferred ; // make the sns subscribe request const params = { Protocol : / ^(https?): / . exec ( config . endpoint ) [ 1 ] , TopicArn : topicArn , Endpoint : config . endpoint } ; config . sns . subscribe ( params , function ( err ) { debug ( 'Subscription request for ' + topicArn + ( err ? ' failed : ' + err . message : ' sent.' ) ) ; if ( err ) return deferred . reject ( err ) ; } ) ; return deferred . promise ; }
Subscribe to an SNS Topic.
@param {string} topicArn
@returns {Promise}
Subscribe to an SNS Topic .