【问题标题】:create a table with a global secondary index error创建全局二级索引错误的表
【发布时间】:2016-01-08 08:10:00
【问题描述】:

我正在尝试使用 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:{“消息”:“意外的键 在 params.GlobalSecondaryIndexes[0] 中找到“AttributeDefinitions”",
“代码”:“UnexpectedParameter”,“时间”:“2016-01-07T18:51:11.659Z”}

【问题讨论】:

    标签: javascript node.js amazon-web-services amazon-dynamodb


    【解决方案1】:

    我终于明白了!我需要从全局索引中删除 AttributeDefinitions,然后将 'fr' 属性的新条目添加到表的 AttributeDefinition 中!

    我要感谢所有在这段艰难时期支持我并容忍我对我的计算机使用不可原谅的语言的人!

    【讨论】:

    • 所以我完全根据这个答案是旧的,你有机会用解决方案的例子来更新答案。我已经完成了你所说的,但我仍然收到这个错误。
    猜你喜欢
    • 2020-11-12
    • 2016-10-28
    • 2022-11-21
    • 2017-10-11
    • 2020-02-27
    • 2023-01-09
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多