如何在 dynamo db 中定义“Map”AttributeType?

Vai*_*til 5 javascript amazon-web-services node.js amazon-dynamodb

我是aws dynamo db 的新手。我读过我们可以M在 dynamo db 的模式中设置attributeValue 的类型。

但是当我执行下面的代码时

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);

});
Run Code Online (Sandbox Code Playgroud)

它不断抛出错误 {"message":"Member must satisfy enum value set: [B, N, S]","code":"ValidationException","time":"2018-02-07T11:20:12.930Z","statusCode":400,"retryable":false}

但是上面的链接说有一个 Map 类型的属性可用。有人可以解释我如何在 dynamo db 中实现 Map。

Mik*_*ike 16

创建 dynamodb 表或向其中添加索引时,只能定义索引的属性。换句话说,您只能定义用于分区键或排序键的属性。就像你在你的例子中所做的那样。但唯一对键有效的属性类型是 S(字符串)、N(数字)和 B(二进制)。映射不是分区键或排序键的有效属性类型,因此在定义表或索引时不能使用它们。

DynamoDB 是无架构的。除了在创建表时为索引键定义的属性之外,您不定义任何属性。如果您想在表格中放置一张地图,只需在放置或更新项目时插入一张地图即可。


Gab*_*leu 1

您可以在此处查找属性定义,唯一允许的值是B, N, S

您应该使用字符串来定义您的地图。