AWS SNS and SQS Example using NodeJS

Using SNS and SQS and Example using NodeJS

Motivation

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

Code

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

Conclusion

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

4 thoughts on “AWS SNS and SQS Example using NodeJS”

  1. Hi,

    Just curious how you came to these prices ($1.50 per message / second).

    SQS Pricing :
    First 1 million Amazon SQS Requests per month are free
    $0.50 per 1 million Amazon SQS Requests per month thereafter ($0.00000050 per SQS Request)
    A single request can have from 1 to 10 messages, up to a maximum total payload of 256KB.
    Each 64KB ‘chunk’ of payload is billed as 1 request. For example, a single API call with a 256KB payload will be billed as four requests.

    SNS is free if you deliver to SQS.

    Cheers,
    Ron

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>