npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aws_message_reader

v3.1.0

Published

Parses an AWS Sns or Dynamodb message. If the callback triggers an error, the original Aws event (lambda_event) is attached to the error object.

Downloads

15

Readme

#Aws Message Reader

Parses an AWS Sns or Dynamodb message. If the callback triggers an error, the original Aws event (lambda_event) is attached to the error object.

Build Status

##Sns message

{
  "Records":[
    {
      "EventSource":"aws:sns",
      "EventVersion": "1.0",
      "EventSubscriptionArn": "arn:aws:sns:us-east-1:123456789012:lambda_topic:0b6941c3-f04d-4d3e-a66d-b1df00e1e381",
      "Sns":{
        "Type": "Notification",
        "MessageId":"95df01b4-ee98-5cb9-9903-4c221d41eb5e",
    "TopicArn":"arn:aws:sns:us-east-1:123456789012:lambda_topic",
        "Subject":"TestInvoke",
    "Message":" SOME STRINGIFIED JSON ",
        "Timestamp":"2015-04-02T07:36:57.451Z",
    "SignatureVersion":"1",
    "Signature":"r0Dc5YVHuAglGcmZ9Q7SpFb2PuRDFmJNprJlAEEk8CzSq9Btu8U7dxOu++uU",
        "SigningCertUrl":"http://sns.us-east-1.amazonaws.com/SimpleNotificationService-d6d679a1d18e95c2f9ffcf11f4f9e198.pem",
    "UnsubscribeUrl":"http://cloudcast.amazon.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:123456789012:example_topic:0b6941c3-f04d-4d3e-a66d-b1df00e1e381",
    "MessageAttributes":{"key":{"Type":"String","Value":"value"}}
      }
    }
  ]
}

Calls back with Records[0].Message parsed json

DynamoDb message

{
    "Records": [
        {
            "eventID": "xx",
            "eventName": "MODIFY",
            "eventVersion": "1.0",
            "eventSource": "aws:dynamodb",
            "awsRegion": "us-east-1",
            "dynamodb": {
                "OldImage": {
                  my_key: {
                    N: '1'
                  },
                  my_string_key: {
                    S: 'SOME STRING'
                  },
                  my_string_set_key: {
                    SS: ['SOME STRING']
                  }
                },
                "NewImage": {
                  my_key: {
                    N: 1
                  },
                  my_string_key: {
                    S: 'SOME STRING'
                  },
                  my_string_set_key: {
                    SS: ['SOME STRING']
                  }
                },
                "SequenceNumber": "xxx",
                "SizeBytes": xxx,
                "StreamViewType": "NEW_IMAGE"
            },
            "eventSourceARN": "arn:aws:..."
        }
    ]
}

Calls back with (parses the Numer type only)

{
    "OldImage": {
      my_key:1,
      my_string_key: 'SOME STRING',
      my_string_set_key:['SOME STRING']
    },
    "NewImage": {
      my_key:1,
      my_string_key: 'SOME STRING',
      my_string_set_key:['SOME STRING']                 
    }
}

#Setup

npm install aws_message_reader

Api

each(iterator, callback)

Under the hood this function is the async.each method.

Applies the function iterator to each item in arr, in parallel. The iterator is called with an item from the list, and a callback for when it has finished. If the iterator passes an error to its callback, the main callback (for the each function) is immediately called with the error.

Note, that since this function applies iterator to each item in parallel, there is no guarantee that the iterator functions will complete in order.


	var messageReader = require('aws_message_reader');

	messageReader(event).each(function(message, cb) {
        // message = JSON.parse(event.Records[0].Sns.Message);
        cb();
  }, function(err) {
    if (err) {

      //err.lambda_event === JSON.stringify(event);

      return callback(err);
    }

    // All done!!
  });