node.js - 一个或多个参数值无效 : dynamodb

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

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));
    }
});

您可以注意到我的主键是yearAttributeName: "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
    }
};

最佳答案

问题是由于您的 KeySchema 不匹配 AttributeDefinitions 引起的。

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

关于node.js - 一个或多个参数值无效 : dynamodb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65931526/

相关文章:

javascript - 使用类的HTML5 Canvas形状(需要Node.js)

amazon-web-services - 暂停 Elastic Beanstalk 应用程序环境?

amazon-web-services - DynamoDB TTL : when are items removed

node.js - NodeJS 应用程序在使用 Upstart 启动时不加载静态文件

javascript - 如何使用 NodeJS 在 Firebase 中构建数据

javascript - 将 Node 文件流图像传递给 HTML5 FileReader API

amazon-web-services - Reservation 类在 AWS EC2 Java SDK 中的作用是什么?

ruby-on-rails-3 - 尝试在 AWS Elastic Beanstalk 上预编译 Assets

node.js - 如何从 DynamoDB 中的 StringSet 中删除项目?

amazon-web-services - Kinesis 客户端库记录处理器故障