use*_*127 1 javascript amazon-web-services node.js amazon-dynamodb
我正在尝试使用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));
}
});
Run Code Online (Sandbox Code Playgroud)
但是我一直收到以下错误,并且未创建表:
无法创建表。错误JSON:{“ message”:“在params.GlobalSecondaryIndexes [0]中找到了意外的键'AttributeDefinitions',
”“ code”:“ UnexpectedParameter”,“ time”:“ 2016-01-07T18:51:11.659Z”}
我终于想通了!我需要从全局索引中删除AttributeDefinitions,然后将“ fr”属性的新条目添加到表的AttributeDefinition中!
我要感谢所有在这段艰难时期为我提供支持,并为我的计算机容忍我无法原谅的语言的人们!
| 归档时间: |
|
| 查看次数: |
1145 次 |
| 最近记录: |