Tag Archives: nodejs

AWS SNS and SQS Example using NodeJS

Using SNS and SQS and Example using NodeJS


I wanted to test out using the new aws-sdk with Amazon Web Services (AWS) SNS and SQS services.  It is now possible to subscribe queues to topics therefore creating a pub/sub style system without any system configuration work.

Setup at AWS

I created a new IAM user in the AWS console and attached the User Policies for Amazon SQS Full Access and Amazon SNS Full Access.

The aws-sdk for NodeJS allows you to have multiple credentials stored in your ~/.aws/credentials file.  See http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html


Then I created code to generate the topic, queue and to subscribe the queue to the topic.  By doing it this way the configuration is stored in code.  No need to log into the AWS console and click through their interface.

Now I can publish messages to the topic and consume them from the queue.

All the code is in github at: https://github.com/markcallen/snssqs

Pros for using SNS/SQS

  • no setup
  • easy to configure
  • easy to program against
  • simple to scale
  • available in all aws regions

Cons for using SNS and SQS

  • can be very expensive – SNS $1.50 + SQS $1.50 per message per request a second
  • SQS 64K package size – max 256K or 4 packages


SNS and SQS are well suited for simpler tasks and workloads with a lower volume of messages.