4

我想通过aws-sdk on nodejsdynamodb上创建一个表。 下面是我传递dynamodb.createTable参数:Nodejs DynamoDB CreateTable哈希只有没有范围返回ValidationException

{ 
    TableName: 'new_table', 
    ProvisionedThroughput: { 
     ReadCapacityUnits: 1, 
     WriteCapacityUnits: 1 
    }, 
    KeySchema: [ 
     {AttributeName: 'primary_key', KeyType: 'HASH'} 
    ], 
    AttributeDefinitions: [ 
     {AttributeName: 'primary_key', AttributeType: 'S'}, 
     {AttributeName: 'some_attribute', AttributeType: 'S'} 
    ] 
} 

这将返回

ValidationException: One or more parameter values were invalid: Number of attributes in KeySchema does not exactly match number of attributes defined in AttributeDefinitions 

我已经解决了这个问题通过增加“some_attribute”上“KeySchema”,但我想要的是一个“哈希'只有桌子没有'范围'。

回答

12

解决方案:创建表时,只需指定KeySchema属性,而不是指定要放在表上的所有属性。所以在我的情况下,我只需要指定'primary_key'

{ 
    TableName: 'new_table', 
    ProvisionedThroughput: { 
     ReadCapacityUnits: 1, 
     WriteCapacityUnits: 1 
    }, 
    KeySchema: [ 
     {AttributeName: 'primary_key', KeyType: 'HASH'} 
    ], 
    AttributeDefinitions: [ 
     {AttributeName: 'primary_key', AttributeType: 'S'}, 
    ] 
} 
+0

谢谢。我也偶然发现了同样的问题。 – YOMorales 2014-12-05 22:10:00