src/create/aws/create-event-lambda-deployments/_get-sns-topic-arn.js
function listTopics(next, done) {
    let params = next? {NextToken:next} : {}
    sns.listTopics(params, function _listTopics(err, result) {
      if (err) {
        done(err)
      }
      else {
        // keep track of our current iteration
        let index = 0
        let tidy = t=> t.TopicArn.split(':').reverse().shift()
        // iterate the topics seeking our name
        result.Topics.map(tidy).forEach(t=> {
          if (t === name) {
            found = result.Topics[index].TopicArn
          }
          index += 1
        })
        // if there are more pages walk those
        let more = result.NextToken && !found
        if (more) {
          listTopics(result.NextToken, done)
        }
        else {
          // otherwise we're done walking
          done()
        }
      }
    })
  }
function listTopics(next, done) {
    let params = next? {NextToken:next} : {}
    sns.listTopics(params, function _listTopics(err, result) {
      if (err) {
        done(err)
      }
      else {
        // keep track of our current iteration
        let index = 0
        let tidy = t=> t.TopicArn.split(':').reverse().shift()
        // iterate the topics seeking our name
        result.Topics.map(tidy).forEach(t=> {
          if (t === name) {
            found = result.Topics[index].TopicArn
          }
          index += 1
        })
        // if there are more pages walk those
        let more = result.NextToken && !found
        if (more) {
          listTopics(result.NextToken, done)
        }
        else {
          // otherwise we're done walking
          done()
        }
      }
    })
  }
function listTopics ( next , done ) { let params = next ? { NextToken : next } : { } sns . listTopics ( params , function _listTopics ( err , result ) { if ( err ) { done ( err ) } else { // keep track of our current iteration let index = 0 let tidy = t => t . TopicArn . split ( ':' ) . reverse ( ) . shift ( ) // iterate the topics seeking our name result . Topics . map ( tidy ) . forEach ( t => { if ( t === name ) { found = result . Topics [ index ] . TopicArn } index += 1 } ) // if there are more pages walk those let more = result . NextToken && ! found if ( more ) { listTopics ( result . NextToken , done ) } else { // otherwise we're done walking done ( ) } } } ) }
aws-sdk isn't the friendliest api we need to recurse thru topics searching for the arn
aws - sdk isn t the friendliest api we need to recurse thru topics searching for the arn