Aws-sdk-js: Parse DynamoDB Stream events?

Created on 22 Feb 2017  路  2Comments  路  Source: aws/aws-sdk-js

Hey

Is there a way to parse DynamoDB Stream events using the SDK? I receive a JSON from a DynamoDB stream in a process, and I would like to parse the NewImage into a "normal" hash, without the types S, M etc as root keys.

The JSON I receive:

{
  "eventID":"",
  "eventName":"MODIFY",
  "eventVersion":"1.1",
  "eventSource":"aws:dynamodb",
  "awsRegion":"us-east-1",
  "dynamodb":{
    "ApproximateCreationDateTime":123,
    "Keys":{
      "object_id":{
        "S":"123"
      }
    },
    "NewImage":{
      "name":{
        "S":"NAME"
      },
      "hash_value":{
        "M":{
          "sub_hash_value":{
            "M":{
              "second_name":{
                "S":"name"
              },

And I would like to parse the NewImage to:

{ 
  "object_id": "123", 
  "name": "name", 
  "hash_value": { 
    "sub_hash_value":  { "second_name": "name" } 
  }
}

Is there any helper in the SDK that parses it?

guidance

Most helpful comment

Hi @marckaraujo,

A PR exposing the DynamoDB DocumentClient's converter has been merged to master and will go out with the next release. To convert the "NewImage" hash in the JSON snippet above to the expected output, you would call AWS.DynamoDB.Converter.output(newImageObject) where newImageObject represents the JSON you receive.

Please feel free to reopen if you have any questions or concerns.

All 2 comments

Hi @marckaraujo,

A PR exposing the DynamoDB DocumentClient's converter has been merged to master and will go out with the next release. To convert the "NewImage" hash in the JSON snippet above to the expected output, you would call AWS.DynamoDB.Converter.output(newImageObject) where newImageObject represents the JSON you receive.

Please feel free to reopen if you have any questions or concerns.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

Was this page helpful?
0 / 5 - 0 ratings