【问题标题】:The number of attributes in key schema must match the number of attributes defined in attribute definitions in AWS DynamoDB?密钥架构中的属性数量必须与 AWS DynamoDB 中属性定义中定义的属性数量匹配吗?
【发布时间】:2023-01-23 17:58:57
【问题描述】:

从 Node Js 在 dynamoDB 中创建表时。我收到上述错误。

const schema = {
TableName: "alarms",
KeySchema: [
    { AttributeName: "alarm_code", KeyType: "HASH" },  //Partition key
    { AttributeName: "controller", KeyType: "RANGE" }  //Sort key
],
AttributeDefinitions: [
    { AttributeName: "alarm_code", AttributeType: "N" },
    { AttributeName: "controller", AttributeType: "S" },
    { AttributeName: "controller_type", AttributeType: "S" }
],
ProvisionedThroughput: {
    ReadCapacityUnits: 10,
    WriteCapacityUnits: 10
}

}

{ AttributeName: "controller_type", AttributeType: "S" }

将此属性添加到 AttributeDefinitions 我收到上述错误

【问题讨论】:

    标签: node.js amazon-dynamodb


    【解决方案1】:

    Amazon DynamoDB 中表的键架构中的属性数量必须与属性定义中定义的属性数量相匹配。

    在 DynamoDB 中,键模式用于定义表的主键。主键由一个或多个属性组成,每个属性都在属性定义中定义。密钥模式必须包括与属性定义中定义的属性完全相同的一组属性,并且顺序相同。这确保了键模式中的属性与属性定义中定义的属性之间存在一对一的映射。

    例如,如果表的主键定义为由“Id”和“Timestamp”两个属性组成的组合键,那么属性定义必须包括这两个属性,并且键模式必须包括这两个属性在同样的顺序。

    需要注意的是,DynamoDB 表的主键必须是唯一的,不能为空。

    【讨论】:

      猜你喜欢
      • 2015-09-01
      • 2016-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      相关资源
      最近更新 更多