9.1 C
Vancouver
Saturday, December 21, 2024

AWS SNS and SQS Example using NodeJS

Must read

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.

More articles

5 COMMENTS

  1. FYI, SNS and SQS only costs few cents for more than a million messages. Greate article anyways 🙂

  2. 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

    • No, the pricing is wrong as other commentators have noted. First 1 million SNS publications are free and SQS to SNS is also free.
      I am interested in this service as a way to send short messages to mobile subscribers which is why this article caught my attention.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article