lib/iam/doesRoleExist.js
function doesRoleExist (iam, roleName) {
  function inspectError (err) {
    if (err.code === 'NoSuchEntity') {
      return false
    }

    return Bluebird.reject(err)
  }

  return iam
    .getRolePromised({ RoleName: roleName })
    .then(_.constant(true))
    .error(inspectError)
}
function doesRoleExist (iam, roleName) {
  function inspectError (err) {
    if (err.code === 'NoSuchEntity') {
      return false
    }

    return Bluebird.reject(err)
  }

  return iam
    .getRolePromised({ RoleName: roleName })
    .then(_.constant(true))
    .error(inspectError)
}
function doesRoleExist ( iam , roleName ) { function inspectError ( err ) { if ( err . code === 'NoSuchEntity' ) { return false } return Bluebird . reject ( err ) } return iam . getRolePromised ( { RoleName : roleName } ) . then ( _ . constant ( true ) ) . error ( inspectError ) }
Uses IAM.getRole to check the existence of the role. If the response comes
back with role data, the promise is resolved with True. If an error
occurs the err is inspected to see if it is a 'NoSuchEntity' / 404 error.
If it is, this means the role does not exist, and the promise is resolved
with False. All other errors result in a rejection.

@returns {Promise}
Uses IAM . getRole to check the existence of the role . If the response comes back with role data the promise is resolved with True . If an error occurs the err is inspected to see if it is a NoSuchEntity / 404 error . If it is this means the role does not exist and the promise is resolved with False . All other errors result in a rejection .