我正在尝试使用nodejs中的javascript SDK创建一个包含全局二级索引的表:
var messagesTableParams = {
TableName : "Messages",
KeySchema: [
{ AttributeName: "to", KeyType: "HASH"}, //Partition key
{ AttributeName: "tm", KeyType: "RANGE" } //Sort key
],
AttributeDefinitions: [
{ AttributeName: "to", AttributeType: "N" },
{ AttributeName: "tm", AttributeType: "N" }
],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
},
GlobalSecondaryIndexes: [
{
IndexName: 'fr_indx',
KeySchema: [
{ AttributeName: "fr", KeyType: "HASH"}, //Partition key
{ AttributeName: "tm", KeyType: "RANGE" } //Sort key
],
AttributeDefinitions: [
{ AttributeName: "fr", AttributeType: "N" },
{ AttributeName: "tm", AttributeType: "N" }
],
Projection: {
ProjectionType: 'KEYS_ONLY'
},
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
}
]
};
dynamodb.createTable(messagesTableParams, function(err, data) {
if (err) {
console.error("Unable to create table. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("Created table. Table description JSON:", JSON.stringify(data, null, 2));
}
});
但是我一直收到以下错误,并且没有创建表:
无法创建表格。错误JSON:{" message":"意外密钥 ' AttributeDefinitions'发现于params.GlobalSecondaryIndexes [0]",
"代码":" UnexpectedParameter"," time":" 2016-01-07T18:51:11.659Z" }
答案 0 :(得分:4)
我终于明白了!我需要从全局索引中删除AttributeDefinitions,然后将'fr'属性的新条目添加到表的AttributeDefinition中!
我要感谢所有在这艰难的时刻支持我的人,并且对我的计算机容忍了我不可原谅的语言!