I am trying to create a simple table using the DynamoDB javascript shell and I get this exception:
{ "message": "The number of attributes in key schema must match the number of attributes defined in attribute definitions.", "code": "ValidationException", "time": "2015-06-16T10:24:23.319Z", "statusCode": 400, "retryable": false }
The following is an Im table trying to create:
var params = { TableName: 'table_name', KeySchema: [ { AttributeName: 'hash_key_attribute_name', KeyType: 'HASH', }, ], AttributeDefinitions: [ { AttributeName: 'hash_key_attribute_name', AttributeType: 'S', }, { AttributeName: 'attribute_name_1', AttributeType: 'S', } ], ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1, }, }; dynamodb.createTable(params, function(err, data) { if (err) print(err); else print(data); });
var params = { TableName: 'table_name', KeySchema: [ { AttributeName: 'hash_key_attribute_name', KeyType: 'HASH', }, ], AttributeDefinitions: [ { AttributeName: 'hash_key_attribute_name', AttributeType: 'S', }, { AttributeName: 'attribute_name_1', AttributeType: 'S', } ], ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1, }, }; dynamodb.createTable(params, function(err, data) { if (err) print(err); else print(data); });
However, if I add a second attribute to keySchema, it works fine. Below the desktop:
var params = { TableName: 'table_name', KeySchema: [ { AttributeName: 'hash_key_attribute_name', KeyType: 'HASH', }, { AttributeName: 'attribute_name_1', KeyType: 'RANGE', } ], AttributeDefinitions: [ { AttributeName: 'hash_key_attribute_name', AttributeType: 'S', }, { AttributeName: 'attribute_name_1', AttributeType: 'S', } ], ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1, }, }; dynamodb.createTable(params, function(err, data) { if (err) print(err); else print(data); });
var params = { TableName: 'table_name', KeySchema: [ { AttributeName: 'hash_key_attribute_name', KeyType: 'HASH', }, { AttributeName: 'attribute_name_1', KeyType: 'RANGE', } ], AttributeDefinitions: [ { AttributeName: 'hash_key_attribute_name', AttributeType: 'S', }, { AttributeName: 'attribute_name_1', AttributeType: 'S', } ], ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1, }, }; dynamodb.createTable(params, function(err, data) { if (err) print(err); else print(data); });
I do not want to add a range to the key scheme. Any idea how to fix this?