Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the recommended way to remove data type descriptors from a DynamoDB response?

DynamoDB includes a data type descriptor for each element in query response, as shown below:

"Item": { 
    "M" : {
        "Age": {"N": "8"},
        "Name": {"S": "Fido"},
        "Vaccinations": {
            "M": {
                "Rabies": {
                    "L": [
                        {"S": "2009-03-17"},
                        {"S": "2011-09-21"},
                        {"S": "2014-07-08"}
                    ]
                },
                "Distemper": {"S": "2015-10-13"}
            }
        }
    }
}

I would like to strip all of these descriptors ("S", "L", "M", etc), so that it looks like the next example, before I JSON.stringify the data.

"Item": {
    "Age": "8",
    "Name": "Fido",
    "Vaccinations": {
        "Rabies": [
            "2009-03-17",
            "2011-09-21",
            "2014-07-08"
         ]
         "Distemper": "2015-10-13"
     }
}

Is there are standard (or recommended) method for doing this?

like image 649
djruss70 Avatar asked Jul 22 '18 00:07

djruss70


People also ask

What is the best way to delete all the data in a DynamoDB table?

With the DynamoDB API, you use the DeleteItem action to delete data from a table, one item at a time. You must specify the item's primary key values. In addition to DeleteItem , Amazon DynamoDB supports a BatchWriteItem action for deleting multiple items at the same time.

How do you clean up DynamoDB?

One way you can remove any DynamoDB table record is via hard delete operations such as DeleteItem or BatchWriteItem with DeleteRequest. These delete operations have to be triggered by administrators or any user who has delete privilege.

What techniques should you use to secure Amazon DynamoDB?

Use the DynamoDB Encryption Client for client-side encryption, in which you encrypt your table data before you send it to DynamoDB. You may choose to do this based on your data's sensitivity and your application's security requirements. For more information, see Client-Side and Server-Side Encryption.

What are three types of data types offered by DynamoDB?

DynamoDB supports the Java Set , List , and Map collection types. The following table summarizes how these Java types map to the DynamoDB types.


2 Answers

They have a converter that you can use.

For instance, here is their example:

var data= {"Item": {
    "Age": {"N": "8"},
    "Name": {"S": "Fido"},
    "Vaccinations": {
        "M": {
            "Rabies": {
                "L": [
                    {"S": "2009-03-17"},
                    {"S": "2011-09-21"},
                    {"S": "2014-07-08"}
                ]
            },
            "Distemper": {"S": "2015-10-13"}
        }
}}};
var marshalled = AWS.DynamoDB.Converter.unmarshall(data);

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/Converter.html

like image 162
amburt05 Avatar answered Sep 25 '22 21:09

amburt05


With sdk version 3 there are a marshall and unmarshall utilities

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_util_dynamodb.html

import { marshall, unmarshall } from '@aws-sdk/util-dynamodb';

try {
  const data = await ddbClient.send(new GetItemCommand(configReadService.params));
  return unmarshall(data.Item) as unknown as ConfigAssets;
} catch (e) {
  console.log('Reading the configuration database failed ', e)
}
like image 28
Interlated Avatar answered Sep 26 '22 21:09

Interlated