Is it possible to listen to AWS SNS notifications without using public callbacks?

Viewed 3035

I'm just getting started with SNS and as far as I see you cannot simply subscribe to the publisher and listen to events. You have to i). create a publically accessible callback (url/email/sms), ii). register it with the service and iii). build a consumer specific to the type of callback.

I want to use an API similar to this:

const client = new SnsClient({
  region: 'eu-west-1',
  topicArn: 'XXX'
})
client.on('connection', (connection) => {
  connection.on('notification', (notification) => {
    // do some work with notification
  })
})

Am I missing something? I want to have X number of web servers listening to a single event (fanout).

For instance my worker might be an EC2 instance on a private subnet, so the available subscriptions: "http(s)", "email", "sms" wouldn't work**. "SQS" could work but you have to set a queue up for each instance and it uses long polling rather than push. "application" and "lambda" are not applicable.

Is AWS SNS suitable for this use case? If not is there an alternative AWS service?

** You might be able to get https to work but only with overly complex roles/dns.

Edit: I think what I want to do is similar to Google Cloud PubSub Subscription or RabbitMQ but using a native (AWS) rather than 3rd party service.

2 Answers

edit: found this npm package: https://www.npmjs.com/package/sqs-consumer allows you to write like so:

consumer.on('message_received', function(message){
  console.log(message)
})

Came here looking for the same as OP. SNS has subscriber options but like you said, you have to manually create the subscriber and handle all of that nonsense. don't use long polling. I'm going to explore something like RXDB or some type of message queue like ZeroMQ or RabbitMQ. Or if it's simple enough of an implementation, just another node server with websockets.

Related