【发布时间】:2015-09-01 04:19:21
【问题描述】:
我正在尝试使用 DynamoDB JavaScript shell 创建一个简单的表,但遇到了这个异常:
{
"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
}
下面是我要创建的表:
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);
});
但是,如果我将第二个属性添加到 KeySchema,它就可以正常工作。工作台下方:
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);
});
我不想将范围添加到键模式。知道如何解决吗?
【问题讨论】:
-
这只发生在 DynamoDBLocal 上吗?当您尝试对实际服务执行相同操作时会发生什么?
-
我还没有 AWS 账户,所以无法针对实际服务进行测试。我正在使用最新版本的本地 DynamoDB (dynamodb_local_2015-04-27_1.0)。
-
我遇到了与 dynamodb_local_2016-04-19 相同的行为
-
没关系,明亮的 TL;DR 说明了一切。
标签: amazon-dynamodb dynamo-local