【问题标题】:One or more parameter values were invalid: dynamodb一个或多个参数值无效:dynamodb
【发布时间】:2021-01-28 13:40:59
【问题描述】:
const dynamoDBConfig = require("../../config/dynamodb");
var AWS = require("aws-sdk");
AWS.config.update(dynamoDBConfig.aws_remote_config);
var dynamodb = new AWS.DynamoDB();

var params = {
    TableName : "year",
    KeySchema: [       
        { AttributeName: "year", KeyType: "HASH"},  //Partition key
        { AttributeName: "title", KeyType: "RANGE" }  //Sort key
    ],
    // other properties, it is the same every time
};
dynamodb.createTable(params, 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));
    }
});

你可以注意到我的主键是year,AttributeName: "year", KeyType: "HASH"。如果我只是更改表名也可以正常工作。但是,当我将AttributeName: "year", KeyType: "HASH" 更改为AttributeName: "anything", KeyType: "HASH" 时,它会产生错误。

Unable to create table. Error JSON: {
  "message": "One or more parameter values were invalid: Some index key attributes are not defined in AttributeDefinitions. Keys: [test, title], AttributeDefinitions: [title, year]",
  "code": "ValidationException",
  "time": "2021-01-28T05:33:33.723Z",
  "requestId": "H4S1BQ5LB4G46S594UTBK4QMVRVVASDASSFGFGF4KQNSO5AEMVJF66Q9ASUAAJG",
  "statusCode": 400,
  "retryable": false,
  "retryDelay": 4.143072370771728
}

当我更改主键属性的名称时,出了什么问题?

完整参数

var params = {
    TableName : "iam",
    KeySchema: [       
        { AttributeName: "test", KeyType: "HASH"},  //Partition key
        { AttributeName: "title", KeyType: "RANGE" }  //Sort key
    ],
    AttributeDefinitions: [       
        { AttributeName: "year", AttributeType: "N" },
        { AttributeName: "title", AttributeType: "S" }
    ],
    ProvisionedThroughput: {       
        ReadCapacityUnits: 10, 
        WriteCapacityUnits: 10
    }
};

【问题讨论】:

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


    【解决方案1】:

    问题是因为您的KeySchema 不匹配 AttributeDefinitions。

    在KeySchema 中有test,而在AttributeDefinitions 中有year。这显然会导致您的问题,因为您不能拥有不属于您的KeySchema 的AttributeDefinitions,也不属于本地或全局二级索引架构的一部分。

    【讨论】:

    • 这行得通,谢谢。你能为我提供一个很好的资源来学习使用 nodejs 的 dynamodb。因为我是这个领域的初学者。
    • 当我执行AttributeDefinitions: [ { AttributeName: "id", AttributeType: "N" }, { AttributeName: "title", AttributeType: "S" }, { AttributeName: "hi",AttributeType:"S" } ] 时,它会生成错误umber of attributes in KeySchema does not exactly match number of attributes defined in AttributeDefinitions
    • @Rahul AttributeDefinitions 必须匹配 KeySchema。我看到你有树 AttributeDefinitions,但架构只能有 2 个。
    • KeySchema: [ { AttributeName: "id", KeyType: "HASH"}, //Partition key { AttributeName: "title", KeyType: "RANGE" } //Sort key ],
    • @Rahul AttributeName: "hi",AttributeType:"S" 是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    相关资源
    最近更新 更多