Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define "Map" AttributeType in dynamo db?

I am new in aws dynamo db. I have read that we can set M type of attributeValue in schema of dynamo db.

But when I execute the code below

var params = {
    TableName: 'product',
    KeySchema: [
        {
            AttributeName: 'productType',
            KeyType: 'HASH'
        },
         {
            AttributeName: 'manufacturer',
            KeyType: 'SORT'
        }
    ],
    AttributeDefinitions: [
        {
            AttributeName: 'productType',
            AttributeType: 'S'
        },
         {
            AttributeName: 'manufacturer',
            AttributeType: 'M'
        }
    ],
     ProvisionedThroughput: {
        ReadCapacityUnits: 1, 
        WriteCapacityUnits: 1, 
    }

};
dynamodb.createTable(params, function(err, data) {
   console.log(err, data);

});

It keeps throwing error {"message":"Member must satisfy enum value set: [B, N, S]","code":"ValidationException","time":"2018-02-07T11:20:12.930Z","statusCode":400,"retryable":false}

But the above link says that there is an attribute of type Map available. Can someone explain me how can I achieve Map in dynamo db.

like image 537
Vaibhav Patil Avatar asked Feb 07 '18 11:02

Vaibhav Patil


2 Answers

When you create a dynamodb table, or add an index to it, you can only define the attributes for the indexes. In other words, you can only define the attributes used for a partition key or sort key. like you are doing in your example. But the only attribute types that are valid for keys are S (string), N (number), and B (binary). Maps are not valid attribute types for either partition or sort keys, so you can't use them when defining your table or index.

DynamoDB is schema-less. You don't define any attributes other than the ones for the index keys at table creation. If you want a map in your table, you simply insert one when you put or update items.

like image 136
Mike Avatar answered Nov 14 '22 21:11

Mike


This is basically the drawback of DynamoDB , vs say MongoDB or couchbase . The other NoSQL Dbs can let you have documents of any shape and index any attribute no matter how deep it is. In DD , you don't have this flexibility - top level attributes which are indexable must be scalar . This is the trade off for speed.

like image 41
Akif Avatar answered Nov 14 '22 21:11

Akif