【问题标题】:DynamoDB Error: Member must have length less than or equal to 2; Member must satisfy enum value set: [HASH, RANGE]DynamoDB 错误:成员的长度必须小于或等于 2;成员必须满足枚举值集:[HASH, RANGE]
【发布时间】:2021-04-05 20:52:32
【问题描述】:

我正在尝试在 DynamoDB 中创建显示在底部的表,但出现此错误。我知道您不能定义多个 PK,但 GSI-PK 也是如此吗?如何修复错误?

2 validation errors detected: Value '[KeySchemaElement(attributeName=VenueID, keyType=HASH), KeySchemaElement(attributeName=VenueName, keyType=Range), KeySchemaElement(attributeName=CheckInID, keyType=HASH)]' at 'globalSecondaryIndexes.1.member.keySchema' failed to satisfy constraint: Member must have length less than or equal to 2; 
Value 'Range' at 'globalSecondaryIndexes.1.member.keySchema.2.member.keyType' failed to satisfy constraint: Member must satisfy enum value set: [HASH, RANGE]

Serverless.yml

resources:
  Resources:
    BeaconTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${self:custom.beaconsTable}
        AttributeDefinitions:
          - AttributeName: BeaconAddr
            AttributeType: S
          - AttributeName: VenueID
            AttributeType: S
          - AttributeName: VenueName
            AttributeType: S
          - AttributeName: CheckInID
            AttributeType: S
        KeySchema:
          - AttributeName: BeaconAddr
            KeyType: HASH
        GlobalSecondaryIndexes:
          - IndexName: BeaconAddr-index
            KeySchema:
              - AttributeName: VenueID
                KeyType: HASH
              - AttributeName: VenueName
                KeyType: Range
              - AttributeName: CheckInID
                KeyType: HASH
            Projection:
                ProjectionType: "ALL"
        BillingMode: PAY_PER_REQUEST

【问题讨论】:

    标签: amazon-web-services amazon-dynamodb serverless-framework


    【解决方案1】:

    如果您需要两个属性的索引,请创建两个索引。您不能拥有一个具有 两个 哈希属性的 BeaconAddr-index 索引。

    另外,我想知道您是否误解了某些内容,因为将您的索引命名为 BeaconAddr-index 而不是在 BeaconAddr 上编入索引似乎很奇怪?你打算做什么?

    【讨论】:

    • 是的,我可能误解了索引命名。我打算根据`beaconAddr`查询一个场地,然后也根据同一个PK查询签到
    猜你喜欢
    • 2019-09-26
    • 2022-07-07
    • 2019-08-22
    • 1970-01-01
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    • 2020-07-27
    • 2020-06-10
    相关资源
    最近更新 更多