4

dynamodb의 테이블을 aws-sdk on nodejs에 만들려고합니다. 는 '해시'KeySchema '하지만 내가 원하는에'some_attribute '를 추가하여범위가없는 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 

내가이 문제를 해결 한 반환 : 다음은 내가 dynamodb.createTable에 전달하고있는 매개 변수입니다 '범위'가없는 테이블 만.

답변

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