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