0

I'm trying to create the table shown at the bottom in DynamoDB but I get this error. I understand that you can't define more than one PK but is that also the case for GSI-PKs? How can I fix the errors?

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

enter image description here

UnknownPerson
  • 114
  • 1
  • 8

1 Answers1

1

If you need indices on two attributes, create two indices. You cannot have one BeaconAddr-index index with two hash attributes.

Also, I wonder if you've misunderstood something because naming your index BeaconAddr-index when it's NOT indexed on BeaconAddr seems odd? What did you intend to do?

JHH
  • 6,514
  • 5
  • 28
  • 64
  • Yeah I may have misunderstood index naming. I intend to query a venue based on the ` beaconAddr ` and then also query check-ins based on the same PK – UnknownPerson Apr 05 '21 at 13:00