lib/ec2/doesSecurityGroupExist.js
function doesSecurityGroupExist (ec2, securityGroupName) {
  function inspectError (err) {
    if (err.code === 'InvalidGroup.NotFound') {
      return false
    }

    return Bluebird.reject(err)
  }

  return ec2
    .describeSecurityGroupsPromised({
      GroupNames: [ securityGroupName ]
    })
    .then(_.constant(true))
    .error(inspectError)
}
function doesSecurityGroupExist (ec2, securityGroupName) {
  function inspectError (err) {
    if (err.code === 'InvalidGroup.NotFound') {
      return false
    }

    return Bluebird.reject(err)
  }

  return ec2
    .describeSecurityGroupsPromised({
      GroupNames: [ securityGroupName ]
    })
    .then(_.constant(true))
    .error(inspectError)
}
Uses EC2.describeSecurity groups to check the existence of the security
group. If the response comes back successful doesSecurityGroupExist is
resolved with True. If an operational error occurs in the underlying ec2
client call, the error is inspected to see if it is an
"InvalidGroup.NotFound" error. This means the security group is not present,
so doesSecurityGroupExist is resolved with false. All other errors are
propagated along via a rejection.

@param ec2
@param securityGroupName

@returns {Promise}